Open other application in startLockTask mode using setLockTaskPackages() string array params in Android 5.0 (Lollipop) is not working

爱⌒轻易说出口 提交于 2019-12-11 15:06:43

问题


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.

来源:https://stackoverflow.com/questions/51190997/open-other-application-in-startlocktask-mode-using-setlocktaskpackages-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!