There are some apps which can detect when they are being removed from Phone/Device Administrator. I've searched on Android developer website and couldn't found out the flag or receiver which triggers when user clicks on that "tick" checkbox beside our application in the Phone/Device Administrator.
Detect App being removed from Phone/Device Administrator
1.1k views Asked by Ahmad Shahwaiz At
2
There are 2 answers
4
On
A device administrator receives the action ACTION_DEVICE_ADMIN_DISABLED when it gets disabled by the user, which you can handle in onDisabled(Context, Intent). You can still use the DevicePolicyManager privileged APIs within the onDisabled method, but not after it returns.
In the Broadcast receiver, there is an callback function which extends from
DeviceAdminReceiver
class which is as follows. Once user clicks the deactivate button this function is calledonDisableRequested
right before disabling the app from device administrator, after user clicks deactivate it callsonDisabled
. First of all we have to call the launcher (home screen) after that lock the device. User won't be able to deactivate if we use this logic. If is there any more optimized way feel free to share/update.