A DPC must whitelist apps before they can be used in lock task mode. Call DevicePolicyManager.setLockTaskPackages()
to whitelist apps for lock task mode as shown in the following sample:
// Whitelist two apps.
private static final String KIOSK_PACKAGE = "com.example.kiosk";
private static final String PLAYER_PACKAGE = "com.example.player";
private static final String[] APP_PACKAGES = {KIOSK_PACKAGE, PLAYER_PACKAGE};
// ...
Context context = getContext();
DevicePolicyManager dpm =
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName adminName = getComponentName(context);
dpm.setLockTaskPackages(adminName, APP_PACKAGES);
you can declare in your app manifest file how an activity should behave when the system is running in lock task mode. To have the system automatically run your activity in lock task mode, set the android:lockTaskMode
attribute to if_whitelisted
android:lockTaskMode="if_whitelisted">
taken from https://developer.android.com/work/dpc/dedicated-devices/lock-task-mode#java