Launch another app in Kiosk Mode from a device owner app in Android Lollipop

3k Views Asked by At

Is there any possibility to start another 3rd party app locked down in Kiosk Mode on Android L? It would be great to be able to do such a thing without the use of root access. But if this is not possible without the use of root access, it would also be a solution to me.

I've successfully developed an app which is the device owner on my device and can use the startLockTask() method to lock itself down into Kiosk Mode.

2

There are 2 best solutions below

0
On

If you have an app that is already device Owner (as you said), you should be able to call from this app:

DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Activity.DEVICE_POLICY_SERVICE);
devicePolicyManager.setLockTaskPackages(new ComponentName(context.getApplicationContext(), YourDeviceOwnerReceiver.class), new String[]{"the.package.you.want.to.allow.to.be.in.kiosk.mode"});

Then, from the activity you want to set in Kiosk mode (which should be in the.package.you.want.to.allow.to.be.in.kiosk.mode), you can call startLockTask().

0
On

If you can lock your own app down in kiosk mode, you can probably launch another app by Intent() with some flags indicating the intent is hosted by your activity to continue your kiosk. You will also have to mess around with the launch mode your app is running in the AndroidManifest. Mess around with singleTop, singleTask and singleInstance until you find what you want. singleTop should be the one you're looking for, but it's hard to discern.

If all else fails, you can always launch your intent and then do a 'adb kill SystemUI' kind of thing through exec("su") in order to kill the status bar, softkeys&hardkeys, and navigation. Depending on device, SystemUI will probably restart itself. You can use a Timer though. Dirty workaround, but that's what kiosk is all about. For code, you can use the answer here: exec su inside Android app

Hope I helped,