/*
* 激活设备管理器
* packageName包名,className 对应Receiver的名称
*/
private void activeAdmin(String packageName,String className) {
DevicePolicyManager mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
try {
ComponentName _componentName=new ComponentName(packageName,className);
mDPM.setActiveAdmin(_componentName,false);
} catch (RuntimeException e) {
e.printStackTrace();
}
}
<receiver android:label="@string/app_name" android:name="xxxxx" android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data android:name="android.app.device_admin" android:resource="@xml/device_admin"/>
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
</intent-filter>
</receiver>
网友评论