Device administration)
Alexzhuang posted a total of 0 comments seven months ago.
Android 2.2 introduces support for enterprise applications by offering the Android device administration API.
Since Android, Android has provided an API for device management. We can use this API to remotely delete data, Set lock screen passwords, and perform other system-level operations.
For details, see: http://developer.android.com/guide/topics/admin/device-admin.html
The following describes how to develop a device management application:
1. Create a broadcast receiver for MyAdmin to inherit deviceadminreceiver
Androidmanifest. xml
<receiver android:name=".MyAdmin"><meta-data android:name="android.app.device_admin"android:resource="@xml/my_admin" /><intent-filter><action android:name="android.app.action.DEVICE_ADMIN_ENABLED" /></intent-filter></receiver>
MyAdmin. Java
package com.alex.mobilesafe.receiver;import android.app.admin.DeviceAdminReceiver;public class MyAdmin extends DeviceAdminReceiver {}
2. Create an XML file: Res/XML/my_admin.xml
<?xml version="1.0" encoding="utf-8"?><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>
3. register the broadcast receiver as the admin device.
DevicePolicyManager manager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);ComponentName mAdminName = new ComponentName(this, MyAdmin.class);if (!manager .isAdminActive(mAdminName)) {Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,mAdminName);startActivity(intent);}
4. Use devicepolicymanager
Lock screen and set the Lock password
DevicePolicyManager manager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);manager.resetPassword("123", 0);manager.lockNow();
Remote Data Deletion
DevicePolicyManager manager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);manager.wipeData(0);