import android.app.admin.DevicePolicyManager;
static final void setMyAdmin(Context context){
try{
ComponentName componentName = new ComponentName("packagename","AdminReceiverName");
DevicePolicyManager policyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
boolean active = policyManager.isAdminActive(componentName);
android.util.Log.d("systemserver","1900 setMyAdmin");
if(!active){
policyManager.setActiveAdmin(componentName, true);
android.util.Log.d("systemserver","1900 setMyAdmin complete");
}
}catch(Exception e){
android.util.Log.e("systemserver","1900 setMyAdmin fail");
e.printStackTrace();
}
}
packagename:应用包名
AdminReceiverName:接收Admin广播接收器
把setMyAdmin()放到startSystemUi启动之后即可
谢谢
1900 20191104 starmini
网友评论