需要系统级别才能执行,注意权限
adb shell dpm set-device-owner com.xxxx/.DeviceReceiver
public void setDeviceOwner(Context context) {
try {
DevicePolicyManager manger=(DevicePolicyManager)context.getApplicationContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName componentName = new ComponentName(pakgname, receivername);
manger.setActiveAdmin(componentName,true);
}catch(Exception e) {
e.printStackTrace();
}
}