How to stop "holding the back button" from escaping "Lock Task mode" on Android 7+
Asked Answered
F

1

5

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.

Feast answered 16/10, 2017 at 13:49 Comment(0)
S
0

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
}
Silique answered 14/4, 2018 at 11:22 Comment(2)
It only happens when a user "holds" the back button for a while, which does not cause onBackPressed() to be called. It's starting to look like it's an ASUS-specific "feature" rather than an Android issue.Feast
Also happens on Samsung A6 tablet. I believe it is Android 7.0+ specific not device. Above response does not resolve issue.Sheeting

© 2022 - 2024 — McMap. All rights reserved.