有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在DeviceAdmin模式禁用时设置身份验证?

我正在创建一个家长控制应用程序,在那里我想把简单的密码验证前禁用管理员模式使用。我正在使用DeviceAdminReceiver。有帮助的想法或示例代码。谢谢


共 (1) 个答案

  1. # 1 楼答案

    不幸的是,没有直接的方法来实现它。然而,有一种解决方法可以通过重写DeviceAdminReceiver的onDisableRequested()方法来完成

    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.

    注意:

    如果您试图显示覆盖屏幕,请注意,禁用弹出窗口和停用屏幕将具有高可见性优先级。任何这样做的尝试都不会有多大帮助。解决方法之一是先锁定屏幕,然后显示叠加屏幕