我无法获得活动,允许用户授予权限的应用程序是一个设备管理员工作。
我的代码如下...
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);应用程序不会崩溃/报告异常。我能做错什么呢?
发布于 2012-05-14 18:05:25
像这样的事情就行了
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()发布于 2016-09-21 00:06:57
这里有一个关于如何做到这一点的明确示例(官方文档here和here缺少一些上下文)
//class that implements DeviceAdminReceiver, defined in the Manifest
ComponentName deviceAdminCN = new ComponentName(context, DeviceAdminReceiverImpl.class)
...
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, deviceAdminCN);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "your explanation for the user here");
startActivityForResult(intent, YOUR_REQUEST_CODE);Here is the reference class used in the official sample app.
https://stackoverflow.com/questions/10581134
复制相似问题