I set my application as a device owner and the screen is pinning when i call startLockTask()
. my problem now when i try to run another application by using this method :
Intent i = getPackageManager().getLaunchIntentForPackage("com.example.test");
startActivityForResult(i,Intent.FLAG_ACTIVITY_NEW_TASK);
(nothing happen) what i have to do to make it run?
Edit : i tried adding
dpm.setLockTaskPackages(deviceAdmin, new String[] { getPackageName() ,"com.example.test"});
its not launching too.
A DPC can remotely stop lock task mode by removing the app package from the allowlist. Call DevicePolicyManager. setLockTaskPackages() , in Android 6.0 (API level 23) or later, and omit the package name from the allowlist array.
Using intents even allows your app to start an activity that is contained in a separate app. An Intent can be explicit in order to start a specific component (a specific Activity instance) or implicit in order to start any component that can handle the intended action (such as "capture a photo").
Tap on Kiosk Lockdown > Android Kiosk Lockdown and lock down the device in either single app or multi-app kiosk mode. Next, choose Peripheral Settings and under Advanced Lock category, enable Lock task mode.
You need to raise a intent, try like this: Uri mUri = Uri. parse("market://details?id=" + packageName); Intent mIntent = new Intent(Intent. ACTION_VIEW, mUri); startActivity(marketIntent);
You should check the app with an applicationId
is installed on the device. for example in your case the applicationId is com.example.test
.
If the app was not installed, you can bring user to a market or let them choose an app.
String packageName = "com.example.test";
.
.
.
Intent i = context.getPackageManager().getLaunchIntentForPackage(packageName);
if (i == null) {
i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("market://details?id=" + packageName));
// Open app in google play store:
// i.setData(Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName));
}
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
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
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