有些应用程序可以检测到它们何时从电话/设备管理员中删除。我在 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/