public class AdminReceiver extends DeviceAdminReceiver {
@Override
public CharSequence onDisableRequested(Context context, Intent intent) {
DevicePolicyManager mDPM =(DevicePolicyManager)getApplicationContext().getSystemService("device_policy");
mDPM.lockNow();
// You can also display overlay screen
return "Are you sure you want to disable the Device admin?";//OR whatever message you would like to display
}
}
根据文件
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.
# 1 楼答案
不幸的是,没有直接的方法来实现它。然而,有一种解决方法可以通过重写DeviceAdminReceiver的onDisableRequested()方法来完成
根据文件
注意:
如果您试图显示覆盖屏幕,请注意,禁用弹出窗口和停用屏幕将具有高可见性优先级。任何这样做的尝试都不会有多大帮助。解决方法之一是先锁定屏幕,然后显示叠加屏幕