且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检测锁屏密码不正确用户在Android中

更新时间:2023-11-07 23:50:40

您可以设置 DeviceAdminReceiver 将被通知失败的密码尝试,以及作为一个成功的密码尝试失败的尝试之后发生的。这会在 Android的设备管理API的文档

You can set up a DeviceAdminReceiver that will be notified about failed password attempts, as well as a successful password attempt that occurred after a failed attempt. This is covered in the documentation of Android's device administration APIs.

请注意,用户必须同意让您的应用程序作为一个设备管理员,通过设置应用程序之前,你会得到这些事件。

Note that the user will have to agree to allow your app to serve as a device administrator, via the Settings app, before you will get these events.

此示例项目演示监听这些事件,再加上设置了密码质量政策。关键的部分是:

This sample project demonstrates listening for those events, plus setting up a password quality policy. The key pieces are:

  • the DeviceAdminReceiver 实施
  • the设备管理元数据,说明什么是管理能力,你的应用程序要
  • 接收器在the清单
  • code在the活动来检测,如果你的应用程序被批准作为设备管理员,如果没有,导致用户在设置现场进行改变
  • the DeviceAdminReceiver implementation
  • the device admin metadata, stating what administrative capabilities your app wants
  • the receiver's entry in the manifest
  • code in the activity to detect if your app is approved to serve as a device administrator and, if not, lead the user to the spot in Settings to make that change