I want to implement a KioskMode
, I'm targeting only Android L
, since this is a very specific App.
I already went through the process of setting my App as DeviceAdmin, and
DevicePolicyManager.isLockTaskPermitted(this.getPackageName())
already returns true
.
I then start a LockTask
via startLockTask()
.
Everything is fine, but when I hold down the backbutton
, the app still exits the kiosk mode.
I have overridden onKeyPress
to show a custom Dialog for unlocking the app, but this does not hinder android to automatically exit my lock task if the user holds down back.
I don't really know what to do at the moment and would be thankful for every input.
I now have overridden
@Override
public boolean onKeyDown(int KeyCode, KeyEvent event)
{
if(KeyCode == KeyEvent.KEYCODE_BACK)
{
BackDownButtonPressed = true;
if(VolDownPressed)
showTaskLockDialog();
return true;
}
else if(KeyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
{
VolDownPressed = true;
if(BackDownButtonPressed)
showTaskLockDialog();
return true;
}
return super.onKeyDown(KeyCode, event);
}
@Override
public boolean onKeyUp(int KeyCode, KeyEvent event) {
if(KeyCode == KeyEvent.KEYCODE_BACK)
{
BackDownButtonPressed = false;
return true;
}
else if(KeyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
{
VolDownPressed = false;
return true;
}
return super.onKeyUp(KeyCode, event);
}
@Override
public void onBackPressed()
{
return;
}
@Override
public boolean onNavigateUp() {
return true;
}
@Override
public boolean dispatchKeyEvent (KeyEvent event)
{
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
return true;
}
return true;
}
@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
//do something or nothing in your case
return true;
}
return super.onKeyLongPress(keyCode, event);
}
For the record, I am using a Samsung SM-T700 Tablet with Cyanogenmod CM12.1
On a device locked in single app kiosk mode, you can use this method to exit kiosk if you have configured the auto-launch delay for the app under Android Kiosk Lockdown > Launcher. Navigate to Policies on your Hexnode MDM console.
When a device exits lock task mode, the user interface returns to the state mandated by existing device policies. When an app runs in lock task mode, other apps and background services can create new windows that Android displays in front of the app in lock task mode.
Call DevicePolicyManager.setLockTaskPackages (), in Android 6.0 (API level 23) or later, and omit the package name from the allowlist array. When you update the allowlist, the app returns to the previous task in the stack. Note: Removing the app from the allowlist in Android 5.0 and 5.1 doesn’t stop lock task mode.
Kiosk local passcode settings. Go to Policies > Select the kiosk policy or create a new policy. Select Kiosk Lockdown > Android Kiosk Lockdown > Kiosk Exit Settings > Configure. Enter the kiosk exit password and Save the policy. When a local kiosk passcode is defined, you need to provide this local passcode to exit the kiosk mode.
Just to close this topic..
I couldn't figure out a perfect solution to this day. My current workaround is receiving an event if the user leaves the kiosk mode and just entering the kiosk mode again.
Sadly this leaves the user with 2 toasts saying "screen unpinned" and "screen pinned", which is unfortunate. But this satisfies my current needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With