gpt4 book ai didi

Android:设备管理:从服务启动设备管理

转载 作者:太空狗 更新时间:2023-10-29 14:27:33 27 4
gpt4 key购买 nike

我无法获得允许用户授予应用程序成为设备管理员工作权限的 Activity 。

我的代码如下...

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()

关于Android:设备管理:从服务启动设备管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10581134/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com