I\'m in the process of evaluating if and how a CF .NET enterprise application can be ported to run on Android devices. The application on Windows Mobile phones are run in ki
In the new Android L Preview, Google has announced Task Locking, which does exactly that. It does seem to need root however.
The L Developer Preview introduces a new task locking API that lets you temporarily restrict users from leaving your app or being interrupted by notifications. This could be used, for example, if you are developing an education app to support high stakes assessment requirements on Android. Once your app activates this mode, users will not be able to see notifications, access other apps, or return to the Home screen, until your app exits the mode.
To prevent unauthorized usage, only authorized apps can activate task locking. Furthermore, task locking authorization must be granted by a specially-configured device owner app, through the
android.app.admin.DevicePolicyManager.setLockTaskComponents()
method.To set up a device owner, follow these steps:
- Attach a device running an Android
userdebug
build to your development machine.- Install your device owner app.
- Create a
device_owner.xml
file and save it to the/data/system
directory on the device.
$ adb root
$ adb shell stop
$ rm /tmp/device_owner.xml
$ echo "" >> /tmp/device_owner.xml
$ echo "&device-owner package=\"\" name=\"*\" />" >> /tmp/device_owner.xml
$ adb push /tmp/device_owner.xml /data/system/device_owner.xml
$ adb reboot
Before using the task locking API in your app, verify that your activity is authorized by calling DevicePolicyManager.isLockTaskPermitted().
To activate task locking, call
android.app.Activity.startLockTask()
from your authorized activity.When task locking is active, the following behavior takes effect:
- The status bar is blank, and user notifications and status information is hidden.
- The Home and Recent Apps buttons are hidden.
- Other apps may not launch new activities.
- The current app may start new activities, as long as doing so does not create new tasks.
- The user remains locked on your app until an authorized activity calls
Activity.stopLockTask()
.