Add a device administrator application to Android
June 09, 2011 15:52:12 Last update: June 09, 2011 15:52:30
Follow these steps to add a device administrator application to Android, i.e., make the application appear in the "Select device administrators" screen (Settings -> Location & Security -> Select device administrators):
- Add a receiver in
AndroidManifest.xml:<receiver android:name="android.app.admin.DeviceAdminReceiver" android:label="@string/admin_app" android:description="@string/admin_app_description" android:permission="android.permission.BIND_DEVICE_ADMIN"> <meta-data android:name="android.app.device_admin" android:resource="@xml/admin_app_config"/> <intent-filter> <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" /> </intent-filter> </receiver>
All elements and attributes listed above are needed. The attributeandroid:descriptionmust be a string resource, not a literal string. Themeta-dataelement points to an XML resource. - Create the meta-data resource
res/xml/admin_app_resource.xml:<device-admin xmlns:android="http://schemas.android.com/apk/res/android"> <uses-policies> <limit-password/> <watch-login/> <reset-password/> <force-lock/> <wipe-data/> </uses-policies> </device-admin>
- Define values for string resources (
res/values/strings.xml):<?xml version="1.0" encoding="utf-8"?> <resources> <string name="admin_app">Admin App Demo</string> <string name="admin_app_description">More detailed description of the admin app</string> </resources>