Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
654 views
in Technique[技术] by (71.8m points)

android - Screen pinning 3rd party apps programmatically

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 device ownership, the user is not asked for the permission to do so.

From the developer website, brief description tells me that it is possible to do what I am trying:

http://developer.android.com/about/versions/android-5.0.html#ScreenPinning

Programmatically: To activate screen pinning programmatically, call startLockTask() from your app. If the requesting app is not a device owner, the user is prompted for confirmation. A device owner app can call the setLockTaskPackages() method to enable apps to be pinnable without the user confirmation step.

This indicates that as a device owner app, I can pin other apps without user confirmation... but I have no idea how to.

I have been able to put my own app into pinned mode.

Any help would be appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...