Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Run another application while task lock

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.

like image 628
Mohammad abumazen Avatar asked Aug 13 '16 13:08

Mohammad abumazen


People also ask

How do I disable task mode lock?

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.

Can an Android app launch another app?

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").

How do I lock my Android in task mode?

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.

How do I redirect an app to another Android?

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);


2 Answers

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);
like image 140
Misagh Avatar answered Oct 13 '22 22:10

Misagh


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

like image 26
werux Avatar answered Oct 14 '22 00:10

werux