我在kiosk模式下有一个应用程序。我使用下面的方法启用kiosk模式,并且可以通过调用startLockTask()进入kiosk模式。
以下是允许自助服务终端模式的方法:
private void enableKioskMode() {
Log.i(TAG, "enableKioskMode");
ComponentName deviceAdmin = new ComponentName(this, AdminReceiver.class);
DevicePolicyManager mDpm = (DevicePolicyManager)
getSystemService (Context.DEVICE_POLICY_SERVICE);
// First of all, to access anything this app must be the device owner.
if (mDpm.isDeviceOwnerApp (getPackageName())) {
// It also needs to be device admin. If it's not, ask to become one.
if (!mDpm.isAdminActive (deviceAdmin) &&
mDpm.isDeviceOwnerApp(getPackageName())) {
Log.i(TAG, "Not device admin. Asking device owner to become one.");
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, deviceAdmin);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
"You need to be a device admin to enable kiosk mode.");
startActivity(intent);
}
// This app is device owner and admin :now set the apps that can use kiosk mode.
else {
mDpm.setLockTaskPackages(deviceAdmin, new String[] {
getPackageName(), "com.application.test1",
"com.aplication.test2"
});
}
}
// This app is not device owner - It can't access anything.
else {
Log.i(TAG, "Not device owner.");
Toast.makeText(this, "This application is not the device owner.", Toast.LENGTH_SHORT).show();
}
}
我可以通过在此应用程序中调用stopLockTask(),切换到com.application.test1,并从该应用程序调用startLockTask()来从此应用程序切换到com.application.test1。
我的问题是,是否可以从原始应用动态锁定另一个应用?即,而不是切换到com.application.test1,我想切换到com.application.test2并使其保持在kiosk模式,而无需再次从com.application.test2调用startLockTask()。我可以从原始应用程序启动startLockTask()吗?