gpt4 book ai didi

android - 检测正在从电话/设备管理员中删除的应用程序

转载 作者:太空宇宙 更新时间:2023-11-03 11:00:05 25 4
gpt4 key购买 nike

有些应用程序可以检测到它们何时从电话/设备管理员中删除。我在 Android 开发者网站上搜索过,但找不到当用户在电话/设备管理员中点击我们应用程序旁边的“勾选”复选框时触发的标志或接收器。

最佳答案

在Broadcast receiver中,有一个从DeviceAdminReceiver类扩展而来的回调函数,如下所示。一旦用户单击停用按钮,此函数就在设备管理员禁用应用程序之前调用 onDisableRequested,在用户单击停用后它调用 onDisabled。首先,我们必须在锁定设备后调用启动器(主屏幕)。如果我们使用此逻辑,用户将无法停用。如果有任何更优化的方式欢迎随时分享/更新。

@Override
public CharSequence onDisableRequested(Context context, Intent intent) {
Intent homeScreenIntent = new Intent(Intent.ACTION_MAIN);
homeScreenIntent.addCategory(Intent.CATEGORY_HOME);
homeScreenIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(homeScreenIntent);
DevicePolicyManager deviceManger;
deviceManger = (DevicePolicyManager) context.getSystemService(
Context.DEVICE_POLICY_SERVICE);
deviceManger.lockNow();
return context.getString("App won't work if you disable this setting");
}

关于android - 检测正在从电话/设备管理员中删除的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45946201/

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