您的位置:首页 > 移动开发 > Android开发

android中device Admin 应用-------就是获得手机的超级用户权限

2013-10-14 23:14 337 查看
1.创建 MyAdmin 的广播接受者 继承 DeviceAdminReceiver

<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>

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>

2.获取IDevicePolicyManager

Method method = Class.forName("android.os.ServiceManager")

.getMethod("getService", String.class);

IBinder binder = (IBinder) method.invoke(null,

new Object[] { Context.DEVICE_POLICY_SERVICE });

mService = IDevicePolicyManager.Stub.asInterface(binder);

3.注册广播接受者为admin设备

ComponentName mAdminName = new ComponentName(this, MyAdmin.class);

if (mService != null) {

if (!mService.isAdminActive(mAdminName)) {

Intent intent = new Intent(

DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);

intent.putExtra
(DevicePolicyManager.EXTRA_DEVICE_ADMIN,

mAdminName);

startActivity(intent);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: