How to stop “holding the back button” from escaping “Lock Task mode” on Android 7+

泄露秘密 提交于 2019-12-06 08:38:28

问题


I'm attempting to use "Lock Task mode", as described on https://developer.android.com/work/cosu.html

My goal is to have a single app running in a "kiosk mode", so that the user cannot leave the app.

I'm using Google's "Test DPC" app from Google Play as the DPC, which I have made the owner of the device via: adb shell dpm set-device-owner com.afwsamples.testdpc/.DeviceAdminReceiver.

It all works really well at keeping a trivial app (which calls startLockTask()) in kiosk mode. (I have added this trivial app to Test DPCs list of apps which are allowed to use "Lock Task mode".)

The problem is that if a user holds the back button, they escape "Lock Task mode" while displaying a confusing toast of "App is pinned: unpinning is not allowed on this device".

Is there a way of stopping this escape mechanism?


Update: The problem occurs on an Asus P00A with Android 7, but does not occur on an Android P00C with Android 6.


回答1:


I have a similar issue if the user clicks the home button (that can destroy the previous activity), next back button

A trick is to desactivate the back button

@Override
public void onBackPressed() {
    // do nothing
}


来源:https://stackoverflow.com/questions/46771951/how-to-stop-holding-the-back-button-from-escaping-lock-task-mode-on-android

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