美文网首页
android P默认授予指定应用Admin管理权限

android P默认授予指定应用Admin管理权限

作者: l900 | 来源:发表于2019-11-04 11:00 被阅读0次

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

相关文章

网友评论

      本文标题:android P默认授予指定应用Admin管理权限

      本文链接:https://www.haomeiwen.com/subject/neirbctx.html