Device admin confirm before DEACTIVATE

2019-07-29 12:40发布

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.

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.

If you observer AppLock application by DoMobile Lab from google play store, you can find that this app is doing the same thing. So there must be some secret behind it.

1条回答
beautiful°
2楼-- · 2019-07-29 13:02

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
    }

}

As per documentation

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.

查看更多
登录 后发表回答