0

I´m doing an app and I´m testing it on devices Samsung galaxy Y (Android 2.3.6) and Engel tablet 7" (Android 4.0.x).

In my app´s code I´m using this snippet in order to wake up the devices(when they are in sleep mode) and works well , but now my problem is that after wake up they never go to sleep mode anymore, only they go if I press the hardware button. Anyone know how I can set the default energy settings after use PowerManager ?.

KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); 
    final KeyguardManager.KeyguardLock kl = km .newKeyguardLock("MyKeyguardLock"); 
    kl.disableKeyguard(); 

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); 
    WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
                                     | PowerManager.ACQUIRE_CAUSES_WAKEUP
                                     | PowerManager.ON_AFTER_RELEASE, "MyWakeLock");
    wakeLock.acquire();
Manuel Allenspach
  • 12,467
  • 14
  • 54
  • 76
JoCuTo
  • 2,463
  • 4
  • 28
  • 44

2 Answers2

0

Try this:

void wakeUpGirls() {
    if (wakeLock != null) {
     wakeLock.release();
    }
   KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
   KeyguardLock keyguardLock = km.newKeyguardLock("TAG");
   getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
  getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

   keyguardLock.disableKeyguard();
   PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
   wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK 
               | PowerManager.ACQUIRE_CAUSES_WAKEUP 
               | PowerManager.ON_AFTER_RELEASE 
               | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "MyWakeLock");

   wakeLock.acquire();
}

void sleepGirls() {
    if (wakeLock != null) {
      wakeLock.release();
        wakeLock = null;
   }
}
Opal
  • 81,889
  • 28
  • 189
  • 210
Madoka Magica
  • 119
  • 1
  • 5
  • Perhaps there is still 1 "not release" wakeLock. So the screen does not turn off . I do not speak English , but I hope will help . – Madoka Magica Jan 20 '15 at 18:24
0

Use this one it works for me

  PowerManager powermanager=  ((PowerManager)getSystemService(Context.POWER_SERVICE));
  WakeLock wakeLock = powermanager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "tag");
            wakeLock.acquire(9000);
            wakeLock.release

  KeyguardManager km =(KeyguardManager)getSystemService(KEYGUARD_SERVICE);
            k1 = km.newKeyguardLock("IN");
            k1.disableKeyguard();
शु-Bham
  • 952
  • 1
  • 7
  • 14