Hello,
For a project that I am working on I want to use Android's unlock
pattern for security purposes.
So, I need to lock the screen, trigger the unlock pattern, and
callback the result to my application.
I have tried the WAKE_LOCK (Power Manager) to lock the screen and
intercept it using Keyguard Manager but following code did not work on
me properly.
I will be happy if someone advice proper solution.
public class ManageKeyguard {
private static KeyguardManager myKM = null;
private static KeyguardLock myKL = null;
public static synchronized void initialize(Context context) {
if (myKM == null) {
myKM = (KeyguardManager) context.getSystemService
(Context.KEYGUARD_SERVICE);
}
PowerManager PM = (PowerManager) context.getSystemService
(Context.POWER_SERVICE);
PowerManager.WakeLock WL = PM.newWakeLock
(PowerManager.PARTIAL_WAKE_LOCK, "myKMLog");
WL.acquire();
}
public static synchronized void disableKeyguard(Context context) {
initialize(context);
if (myKM.inKeyguardRestrictedInputMode()) {
myKL = myKM.newKeyguardLock("myKMLog");
myKL.disableKeyguard();
System.out.println("--Keyguard disabled");
} else {
myKL = null;
}
}
public static synchronized boolean inKeyguardRestrictedInputMode()
{
if (myKM != null) {
System.out.println("--
inKeyguardRestrictedInputMode = " + myKM.inKeyguardRestrictedInputMode
());
return myKM.inKeyguardRestrictedInputMode();
}
return false;
}
public static synchronized void reenableKeyguard() {
if (myKM != null) {
if (myKL != null) {
myKL.reenableKeyguard();
myKL = null;
System.out.println("--Keyguard
reenabled");
}
}
}
public static synchronized void exitKeyguardSecurely(final
LaunchOnKeyguardExit callback) {
if (inKeyguardRestrictedInputMode()) {
System.out.println("--Trying to exit keyguard
securely");
myKM.exitKeyguardSecurely(new OnKeyguardExitResult
() {
public void onKeyguardExitResult(boolean
success) {
reenableKeyguard();
if (success) {
System.out.println("--
Keyguard exited securely");
callback.LaunchOnKeyguardExitSuccess();
} else {
System.out.println("--
Keyguard exit failed");
}
}
});
} else {
callback.LaunchOnKeyguardExitSuccess();
}
}
public interface LaunchOnKeyguardExit {
public void LaunchOnKeyguardExitSuccess();
}
}
Regards,
Niklaus
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---