问题
I am working on an Android App in which one of the activity has to be completed if user enter a wrong passcode in android lock screen. For example an email sent if user entered a wrong passcode..
I will appreciate any help. Thanks in advance.
Kshitij
回答1:
The lock screen are running in a total sandbox environment which makes it makes it inaccessible.You can create a different Application acting as the lock screen and disabling the default android version.
回答2:
You can do this by registering your app as Device Administrator.
Add watch-login
tag to device admin metadata and then you will be able to handle onPasswordFailed
and onPasswordSucceeded
events.
create a file named device_admin.xml
in your res/xml folder and put these tags inside it:
<?xml version="1.0" encoding="utf-8"?>
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<watch-login />
</uses-policies>
</device-admin>
then you need to create a AdminReciever
class that extends from DeviceAdminReceiver
. inside this class you can handle onPasswordFailed
and do what you need if user entered incorrect password.
you can see full example here:
Password Enforcer Sample
NOTE
as far as i know, this works only with Password and PIN and Patterns is not supported.
来源:https://stackoverflow.com/questions/7782685/how-to-know-if-users-entered-a-wrong-passcode-lock-screen-in-android-app