我无法获取允许用户授予应用程序作为设备管理员工作权限的活动。
我的代码如下…
ComponentName comp = new ComponentName(this, CustomReceiver.class);
Intent i = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
i.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, comp);
i.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Explanation");
startActivity(i);
应用程序不会崩溃/报告异常。我会做错什么?
最佳答案
这样就行了
if (!mPolicy.isAdminActive()) {
Intent activateDeviceAdminIntent =
new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
activateDeviceAdminIntent.putExtra(
DevicePolicyManager.EXTRA_DEVICE_ADMIN,
mPolicy.getPolicyAdmin());
// It is good practice to include the optional explanation text to
// explain to user why the application is requesting to be a device
// administrator. The system will display this message on the activation
// screen.
activateDeviceAdminIntent.putExtra(
DevicePolicyManager.EXTRA_ADD_EXPLANATION,
getResources().getString(R.string.device_admin_activation_message));
startActivityForResult(activateDeviceAdminIntent,
REQ_ACTIVATE_DEVICE_ADMIN);
}
也许你没有考虑
mPolicy.getPolicyAdmin()