Device admin confirm before DEACTIVATE
Asked Answered
P

1

1

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.

Polymath answered 27/10, 2016 at 10:57 Comment(0)
S
1

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.

Sternick answered 26/3, 2018 at 9:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.