I\'m developing an application which runs as an Admin
.
I\'m able to do it using the following code
DemoDeviceAdminReceiver.jav:
Couple of years late, but I just ran into the same problem and was able to solve it. Maybe the OP won't need the answer, but others - like me - might stumble over this in search for a solution.
Keep in mind that this only works if the user can NOT unlock the screen.
All you need to do is lock the screen in DeviceAdminReceiver's onDisableRequested method, so that the user will have to enter their password for unlocking.
Keep in mind that this method is intended to display a warning explaining why the user should not disable permissions. If null (the default from super) is returned, nothing is displayed and the permission is disabled anyway. So if we return any text, a dialog with that text as well as an ok and a cancel button will be displayed.
If you combine that with the screen lock like this:
public CharSequence onDisableRequested(Context context, Intent intent) {
DevicePolicyManager deviceManger = (DevicePolicyManager)context.getSystemService(
Context.DEVICE_POLICY_SERVICE);
deviceManger.lockNow();
return "Your warning";
}
the screen will turn off when the user tries to disable the permission, when they unlock the screen, they're required to enter their password. Once they did that they see a dialog with your warning, the cancel button and an ok button. Only if they then press Ok will the permission be disabled.