Perform calls in Android Locktask mode

喜你入骨 提交于 2021-01-24 08:15:37

问题


TL;DR How to make a phone call while using Activity.startLockTask()?

I'm trying to setup a restricted environment on an Android device, i.e. what is usually called "Kiosk-Mode".

Official documentation can be found here: https://developer.android.com/work/cosu.html

The official way of doing this suggest to use Activity.startLockTask.

This works fine until you want to start other apps from within your Activity which is in startLockTask() mode. Any activity that launches must not start on a new task stack otherwise the system blocks the launch intent, i.e. no Intent.FLAG_ACTIVITY_NEW_TASK.

Some apps can just be launched, other seem to implicitly set this flag, but can be workedaround by using startActivityForResult(...) which seems remove the NEW_TASK flag. For apps that still don't work I could code my own replacement.

The real issue is the call application, which enforces a new task stack. Triggering a call initiated the call, doesn't show the call activity, but also puts a call notification in the status bar (which is not accessible in while using startLockTask(). In contrast to other apps the call app is also one that can't be replaced with a custom app...

DevicePolicyManager.html.setLockTaskPackages() has no effect on this behavior.


回答1:


I tried to make start call intent under locked mode and this line pop up:

    system_process E/ActivityManager: Attempted Lock Task Mode violation mStartActivity=ActivityRecord{56ab302 u0 com.android.server.telecom/.components.UserCallActivity t155}

So I add

    setLockTaskPackages(<ComponentName>,new String[]{getPackageName(),"com.google.android.dialer","com.android.server.telecom"});

Managed to get the dialler out. Of course if I push the home button or back button, there's no way to get the dialler back... the recent button is still locked though. Receiving call works perfectly (all buttons are disabled)




回答2:


Have you tried this?

setLockTaskPackages(new ComponentName(this, DeviceAdminReceiver.class),new String[]{getPackageName(),"com.google.android.dialer"});


来源:https://stackoverflow.com/questions/41806416/perform-calls-in-android-locktask-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!