1

I'm trying to turn the screen on when the app sends a notification. Currently when I acquire a WakeLock it flashes on and off very quickly, almost un-noticeably. As far as I can tell I have my flags set correctly. AQUIRE_CAUSES_WAKEUP to turn the screen on and ON_AFTER_RELEASE to (poke the user activity timer) leave it on once I release it - otherwise, I understand it turning itself off immediately... Anyone got an insight?

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "TAG");
if(mTurnScreenOn) {
        wl.acquire();
        Log.d("TAG", "WakeLock Acquired");
        if(pm.isScreenOn()) { Log.d("TAG", "Screen is on");
        } else { Log.d("TAG", "Screen is off"); }
}

mNotificationManager.notify(1, notification);

if(mTurnScreenOn) { //release the wakelock if needed
        wl.release();
        Log.d("TAG", "WakeLock Released");
        if(pm.isScreenOn()) { Log.d("TAG", "Screen is on");
        } else { Log.d("TAG", "Screen is off"); }
}
bwoogie
  • 4,339
  • 12
  • 39
  • 72

1 Answers1

0

where you are setting the value of mTurnScreenOn , Look at your code you are acquiring wake lock when mTurnScreenOn==true and on same condition your are releasing it also.

for more info see this

Community
  • 1
  • 1
Pawan
  • 1,503
  • 2
  • 19
  • 28
  • That's working fine. It's a preference if the user wants the screen to be turned on when being notified. The LogCat is reporting Screen On when the wakelock is acquired and Screen Off when it's released. So I know its working - It's just turning off before it should. – bwoogie Nov 25 '11 at 05:10
  • you are not getting what I want to say, its like you switch ON button and after its ON you are againg switching OFF by yourself only... Its working I know, but release wake lock some where else. – Pawan Nov 25 '11 at 05:20
  • Ok, mTurnScreenOn has nothing to do with the actual WakeLock. But I see what you're saying... But I don't really have another place to release it. Maybe I just need to make a timer? – bwoogie Nov 25 '11 at 05:25
  • onPause() is right place , and onResume() acquire it again. Have you gone through that link.. ? – Pawan Nov 25 '11 at 05:34
  • yup. putting it in a timer fixed it. but i still dont understand why ON_AFTER_RELEASE isnt working... – bwoogie Nov 25 '11 at 05:37
  • Do you know what exactly `ON_AFTER_RELEASE` does, not ? then check it here http://developer.android.com/reference/android/os/PowerManager.html also check you logic, what an when you exactly want to aquire wake lock.. – Pawan Nov 25 '11 at 05:48