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.
Here's a code snippet that should get you going:
I've not enough reputation for a comment, just would point out that for devices with physical buttons (like the Samsung Galaxy Tab A mentioned by @chairman) one way for manage the forced unpinning of your application is to implement in your DeviceAdminReceiver class the following:
So if your user want to for the unpin you can always re-pinning your app ;)
The
setLockTaskPackages()
is used the specify which applications (through their package names) will be able to programmatically be pinned without user confirmation. ThesetLockTaskPackages()
is called from your device owner app (most probably in yourDeviceAdminReceiver
'sonEnabled()
method).So, in you owner device app, you'll have something like :
and then, in your "com.foo.myapp" application, you will be autorized to call :
Your application will immediately enter the Pinning mode, without any user confirmation.
If you don't first
register
your application withsetLockTaskPackages
, the application will be pinned but the user will have to confirm first.Also notice that when an app is
registered
withsetLockTaskPackages()
, it has some different behaviours than the manual pin:stopLockTask()
;