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

1.创建 MyAdmin 的广播接受者 继承 DeviceAdminReceiver



android:resource="@xml/my_admin" />








my_admin.xml




       
               
               
               
               
               
       




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);
}
}

你可能感兴趣的:(android中device Admin 应用-------就是获得手机的超级用户权限)