I have done these two tasks separately, but I find that when I wake the device *and* unlock the keyguard they do not both happen. I'm sure that's just a bug in my code. So, treat this sample with a pinch of salt, and if you can work out what I did wrong please let me know.
PowerUp() is simple enough. UnlockKeyguard() should be called when you want to show your activity, and ExitKeyguard() should be called when you want to leave your activity for somewhere else To see the full cycle of keyguard unlocking, you need to test with and without the 'Require Pattern' setting enabled. Good luck! Richard private void PowerUp() { PowerManager pm = (PowerManager) getSystemService (Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock( PowerManager.SCREEN_DIM_WAKE_LOCK | // could use bright instead PowerManager.ACQUIRE_CAUSES_WAKEUP | // so we actually wake the device PowerManager.ON_AFTER_RELEASE // and we keep it on for a bit after release , "My Tag"); wl.acquire(); wl.release(); } private void UnlockKeyguard() { if( mKeyguardLock != null ) { return; // already unlocked } KeyguardManager kg = (KeyguardManager ) getSystemService (Context.KEYGUARD_SERVICE); if( kg.inKeyguardRestrictedInputMode()) { mKeyguardLock = kg.newKeyguardLock( "My Tag" ); mKeyguardLock.disableKeyguard(); } else { mKeyguardLock = null; // make sure we are tidy } } private void exitKeyguard() { if( mKeyguardLock != null ) // we disabled keyguard { KeyguardManager kg = (KeyguardManager ) getSystemService (Context.KEYGUARD_SERVICE); if( kg.inKeyguardRestrictedInputMode()) { kg.exitKeyguardSecurely(this); // show the user the keyguard, so they can dismiss it - response happens via the callback onKeyguardExitResult } else { mKeyguardLock = null; doButtonAction(); // do the actions we wanted to do bu had to defer till the user unlocked us } } else { doButtonAction(); } } public void onKeyguardExitResult(boolean success) { if( success ) { mKeyguardLock = null; // don't want this any more doButtonAction(); } else { // user didn't dismiss keyguard, doing nothing if( mKeyguardLock != null ) // should never be null mKeyguardLock.reenableKeyguard(); } } On Feb 23, 11:24 pm, SteveV <sav74...@gmail.com> wrote: > Does anyone know how to do this correctly? > > I can't find any examples & the API documentation is pretty hard to > follow. > > I am guessing I need to use the KeyGuardManager and PowerManager... > but can't figure out how to bring my activity up past the keyguard and > re-enable the keyguard so my activity doesn't let someone get past the > lock when my activity awakens. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---