Well, I have good news and bad news. I can reliably turn the device on
& keep it on for a few seconds, as seen below.


        private void PowerUp()
        {
                PowerManager pm = (PowerManager) getSystemService
(Context.POWER_SERVICE);

                cancelWakeLock();

                 mWakeLock = pm.newWakeLock(
                                                                
PowerManager.FULL_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 - seem to actualy stop the device powering up when
not on charge
                                                                , "my tag");
                 mWakeLock.acquire();



                 mPowerTimer = new Timer();


                 mPowerTimer.schedule(
                                 new TimerTask()
                                 {
                     @Override
                     public void run()
                     {
                          System.out.println("Power timer -
releasing");
                          cancelWakeLock();
                     }
                                 }
                         , 10000);





        }

        private void cancelWakeLock()
        {
                if( mWakeLock != null )
                {
                        mWakeLock.release();
                        mWakeLock = null;
                }
        }



On Feb 25, 9:30 am, jarkman <[email protected]> wrote:
> Steve - you're doing exitKeyguardSecurely, and I think you should be
> doing disableKeyguard.
>
> Chronologically, when the unlock pattern is turned on, I think the
> sequence should be:
>  - Keyguard is on
>  - You call disableKeyguard
>  - The keyguard goes away
>  - You show your  activity, which should not let the user do anything
> dangerous
>  - The user does something to leave your activity
>  - You call exitKeyguardSecurely
>  - The unlock pattern shows
>  - The user unlocks it
>  - your onKeyguardExitResult is called
>  - then you can do the work you wanted to do as a result of the user's
> input on your activity
>
> I also had trouble with onPause being called at times I was not
> expecting during this process. I recommend lots of tracing!
>
> None of that helps with the power stuff, of course. My next experiment
> will be to actually hold the wakelock for several seconds. I'd love to
> see a working sample for this stuff....
>
> Richard
>
> On Feb 25, 8:10 am, SteveV <[email protected]> wrote:
>
> > Thanks for sharing...
> > I had the following code.. which works on the emulator, but I can't
> > get it to work on my phone (with or without the pattern lock enabled):
>
> > I had a line in my onPause that calls reenableKeyguard(), if
> > unlocked==true.
> > I'll keep trying - I noticed your code uses
> > PowerManager.ON_AFTER_RELEASE. I'll report back if adding that helps
> > or if I figure it out myself.
>
> >                 //wake phone
> >                 Log.d(TAG, "mWakeLock.acquire/release()");
> >                 PowerManager pm = (PowerManager) getSystemService
> > (Context.POWER_SERVICE);
> >                 mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK
> >                                 | PowerManager.ACQUIRE_CAUSES_WAKEUP, 
> > "TEST");
> >                 mWakeLock.acquire();
> >                 mWakeLock.release();
>
> >                 //unlock phone
> >                 KeyguardManager km = (KeyguardManager) getSystemService
> > (Context.KEYGUARD_SERVICE);
> >                 mKeyguardLock = km.newKeyguardLock("TEST");
> >                 if (km.inKeyguardRestrictedInputMode()){
> >                         km.exitKeyguardSecurely(new 
> > KeyguardManager.OnKeyguardExitResult(){
> >                                 @Override
> >                                 public void onKeyguardExitResult(boolean 
> > success) {
> >                                         if (success){
> >                                                 Log.d(TAG, 
> > "onKeyguardExitResult success");
> >                                         } else {
> >                                                 Log.d(TAG, 
> > "onKeyguardExitResult ! success");
> >                                         }
> >                                 }
> >                         });
> >                         Log.d(TAG, "inKeyguardRestrictedInputMode - 
> > disableKeyguard");
> >                         mKeyguardLock.disableKeyguard();
> >                         unlocked = true;
> >                 }
>
> > On Feb 24, 10:22 am, jarkman <[email protected]> wrote:
>
> > > As far as I can tell, my PowerManager code works properly when the
> > > device is on charge, but generally doesn't wake the device up when it
> > > is not on charge. I shall keep digging. Perhaps I need to hold the
> > > wakelock for longer to stop it snoozing.
>
> > > R
>
> > > On Feb 23, 11:24 pm, SteveV <[email protected]> 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 [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
-~----------~----~----~----~------~----~------~--~---

Reply via email to