Open other application in startLockTask mode using

2019-08-23 15:19发布

Motive: Building a KIOSK App for 5.0 & 6.0+ devices

Method followed: adb to run the “dpm set-device-owner” command.

By using startLockTask(); my app entered into authorised pin mode successfully.

I had other challenge which is, I have to open other of my installed application from KIOSK app. I achieved this by constructing array of string packages and set it to DPM's setLockTaskPackages below is the code sample

mDevicePolicyManager.setLockTaskPackages(mAdminComponentName, getKioskApps());

private String[] getKioskApps() {
    return (new String[]{getPackageName(),
            "com.test.sampleappone",
            "com.test.sampleapptwo"});
} 

with this above code on 6.0 + devices I can able to navigate sampleAppOne (com.test.sampleappone) & sampleAppTwo (com.test.sampleapptwo) successfully which is installed in my device & below is the navigation code.

private void openSampleAppOne() {

        Intent intentInv = new Intent();
        intentInv.setComponent(new ComponentName("com.test.sampleappone", "com.test.sampleappone.MainActivity"));
        intentInv.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intentInv);
}

the above code is working perfect in 6.0 (marshmallow) & 7.0 (Nougat) devices but not in 5.0 (lollipop) device, which is my challenge now to do.

as per the android documentation setLockTaskPackages will be support from API level 21 which is lollipop 5.0 but I don't know what I missed here to make the code work in 5.0.

Thanks for the time & help to solve this problem.

0条回答
登录 后发表回答