设备管理员在停用之前确认 [英] Device admin confirm before DEACTIVATE

查看:133
本文介绍了设备管理员在停用之前确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在为我的应用程序禁用/禁用设备管理员之前要求确认。我对此进行了很多搜索,但没有找到合适的解决方案。

I want to ask a confirmation before disabling/deactivating device admin for my application. I searched a lot about it but not fing any proper solution for this.

总之,我想在用户单击设备管理员的DEACTIVATE按钮时检测到回调,询问使用确认信息,确定是否要停用设备管理员?如果使用按取消,则不应停用设备管理员。

In short, I want to detect a callback when user click DEACTIVATE button from device admin and I want to ask a confirmation to use that whether are you sure you want to deactivate device admin ? If use press cancel then device admin should not be deactivated.

如果您从Google Play商店观察DoMobile Lab的AppLock应用程序,则可以发现该应用程序是做同样的事情。因此,背后必须有一些秘密。

推荐答案

您可以通过覆盖 onDisableRequested() DeviceAdminReceiver的方法

You can do it by overriding onDisableRequested() method of DeviceAdminReceiver

public class AdminReceiver extends DeviceAdminReceiver {
    @Override
    public CharSequence onDisableRequested(Context context, Intent intent) {
        return "Are you sure you want to disable the Device admin?";//OR whatever message you would like to display
    }

}

根据文档


当用户由于收到ACTION_DEVICE_ADMIN_DISABLE_REQUESTED而要求禁用管理员时调用,从而有机会向他们显示警告消息。消息作为结果返回;如果返回null(默认实现),则不会显示任何消息。

Called when the user has asked to disable the administrator, as a result of receiving ACTION_DEVICE_ADMIN_DISABLE_REQUESTED, giving you a chance to present a warning message to them. The message is returned as the result; if null is returned (the default implementation), no message will be displayed.

这将显示一个带有确定和取消按钮的弹出窗口,以及返回的文本。

This will show a popup with OK and cancel button, along with the text returned.

这篇关于设备管理员在停用之前确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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