如何通过设置菜单防止用户禁用我的设备管理应用程序? [英] How to prevent a user from disabling my device admin app, through the settings menu?

查看:79
本文介绍了如何通过设置菜单防止用户禁用我的设备管理应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Android开发MDM(移动设备管理)应用程序,但是我遇到了一个很大的问题,那就是用户可以在设置">安全性">设备管理员"中禁用我的应用程序.我唯一能做的就是通过覆盖DeviceAdminReceiver子类中的onDisableRequested(...)方法来显示警告消息,但是我真的想防止用户完全禁用我的管理应用程序.

I'm working on an MDM (Mobile Device Management) app for android, but I have a huge problem and it's that the user can disable my app from within settings>security>device administrators. The only thing I can do about it, is display a warning message by overriding the onDisableRequested(...) method in my DeviceAdminReceiver sub-class, but I really want to prevent the user from disabling my admin app altogether.

我试图覆盖onReceive(...)方法,因此当系统广播动作ACTION_DEVICE_ADMIN_DISABLE_REQUESTED和ACTION_DEVICE_ADMIN_DISABLED时,什么也没有发生,但到目前为止它没有起作用.显然,其他组件正在处理这些动作,直到它们到达我的onReceive(...)方法为止,我不知道为什么.我希望能够显示自己的自定义对话框,指示用户无法从本节中禁用管理员应用程序,甚至可能要求用户设置管理员密码来完成此操作.

I've tried to override the onReceive(...) method, so that nothing happens when the actions ACTION_DEVICE_ADMIN_DISABLE_REQUESTED and ACTION_DEVICE_ADMIN_DISABLED are broadcasted by the system, but so far it has not worked. Apparently some other component is processing those actions before they arrive to my onReceive(...) method and I dont know why. I would like to be able to show my own custom dialog indicating that the user can´t disable the administrator app from this section, and maybe even ask the user to set an admin password to do it.

public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (ACTION_PASSWORD_CHANGED.equals(action)) {
            onPasswordChanged(context, intent);
        } else if (ACTION_PASSWORD_FAILED.equals(action)) {
            onPasswordFailed(context, intent);
        } else if (ACTION_PASSWORD_SUCCEEDED.equals(action)) {
            onPasswordSucceeded(context, intent);
        } else if (ACTION_DEVICE_ADMIN_ENABLED.equals(action)) {
            onEnabled(context, intent);
        } else if (ACTION_DEVICE_ADMIN_DISABLE_REQUESTED.equals(action)) {

        } else if (ACTION_DEVICE_ADMIN_DISABLED.equals(action)) {

        } else if (ACTION_PASSWORD_EXPIRING.equals(action)) {
            onPasswordExpiring(context, intent);
        }
    }  

我需要帮助来解决此问题.

I need help to solve this issue.

谢谢

推荐答案

您可以使用新的设备所有者模式在Android 5 Lollipop中执行此操作.然后,Device-Administrator选项显示为灰色,用户无法禁用它,因此不能卸载device-admin应用程序.

You can do this from Android 5 Lollipop with the new device-owner mode. Then the Device-Administrator option in greyed-out and the user cannot disable it, thus not uninstall the device-admin App.

但是请注意,安装设备所有者应用程序并不容易,必须在供应时使用NFC或从具有adb的计算机(方便进行测试但不能进行部署)或MDM上进行安装你的情况...

However note that installing a device-owner App is not easy, it has to be done at provision-time with NFC, or from a computer with adb (handy for testing but not for deployment), or with a MDM what is your case...

这篇关于如何通过设置菜单防止用户禁用我的设备管理应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆