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

2019-11-04  本文已影响0人  l900

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

上一篇 下一篇

猜你喜欢

热点阅读