Android 2.2 introduces support for enterprise applications by offering the Android Device Administration API. html
從Android2.2 起,Android官方就提供了設備管理API,咱們能夠經過這個API實現遠程刪除數據、設置鎖屏密碼等系統級別的操做。java
具體詳見:http://developer.android.com/guide/topics/admin/device-admin.htmlandroid
下面就是設備管理應用程序開發的簡化實現步驟:app
1.建立 MyAdmin 的廣播接受者 繼承 DeviceAdminReceiveride
AndroidManifest.xmlui
<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.javathis
package com.alex.mobilesafe.receiver; import android.app.admin.DeviceAdminReceiver; public class MyAdmin extends DeviceAdminReceiver { }
2. 建立XML文件:res/ xml /my_admin.xmlcode
<?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.註冊廣播接受者爲admin設備xml
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.使用DevicePolicyManager htm
鎖屏並設置鎖頻密碼
DevicePolicyManager manager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); manager.resetPassword("123", 0); manager.lockNow();
遠程刪除數據
DevicePolicyManager manager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); manager.wipeData(0);