Screen pinning 3rd party apps programmatically

前端 未结 3 1990
刺人心
刺人心 2020-12-13 21:18

After achieving device ownership, I am trying to implement a method to instruct the device to lock any given app into kiosk mode (or screen pinning mode). Since I have devic

3条回答
  •  一向
    一向 (楼主)
    2020-12-13 21:39

    The setLockTaskPackages() is used the specify which applications (through their package names) will be able to programmatically be pinned without user confirmation. The setLockTaskPackages() is called from your device owner app (most probably in your DeviceAdminReceiver's onEnabled() method).

    So, in you owner device app, you'll have something like :

    mDPM.setLockTaskPackages("com.foo.myapp");
    

    and then, in your "com.foo.myapp" application, you will be autorized to call :

    startLockTask(); 
    

    Your application will immediately enter the Pinning mode, without any user confirmation.

    If you don't first register your application with setLockTaskPackages, the application will be pinned but the user will have to confirm first.

    Also notice that when an app is registered with setLockTaskPackages(), it has some different behaviours than the manual pin:

    • the user cannot unpin manually the application by long-pressing Back + Recent Apps. You'll have to programmatically unpin your app with stopLockTask();
    • The "Home" and "Recent Apps" buttons are invisible (not displayed)
    • When the app is unpinned (via stopLockTask()), the user will directly go back to Home : no Screen lock is displayed, even if a Keyguard is set (Pattern, code, or whatever Keyguard screen).

提交回复
热议问题