Detect Lock Screen Incorrect Password by user in Android

user2166895 picture user2166895 · Apr 5, 2014 · Viewed 12k times · Source

I am building a security app and I need to know if the user is giving incorrect password . Suppose user phone is locked by pattern lock system , and unfortunately user has forgotten the pattern password.When user give wrong pattern 5 time, there will be a penalty for 30 sec . I need to catch that penalty event . In my app, i have to do some task (for the safety of user) when this even come . Please help me,

Answer

CommonsWare picture CommonsWare · Apr 5, 2014

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: