Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turning on screen programmatically

Tags:

I would like to unlock screen and switching it on to show a popup on an event trigger. I am able to unlock the screen using

newKeyguardLock = km.newKeyguardLock(HANDSFREE); newKeyguardLock.disableKeyguard(); 

on KeyGuardService but I cannot turn on the screen. I am using

wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, HANDSFREE); wl.acquire(); 

but with no success. The screen still remains off. How can I achieve this?

like image 534
Matroska Avatar asked May 23 '10 10:05

Matroska


People also ask

How do I turn my screen on Android?

Method #1: Enable the double-tap gesture to turn on the phone screen. One of the easiest and quickest ways to turn on your Android phone's screen without using the power button is by enabling the double-tap gesture in settings.


1 Answers

Note from author: I wrote this back in 2012. I don't know if it works anymore. Be sure to check out the other more recent answers.


Amir's answer got me close, but you need the ACQUIRE_CAUSES_WAKEUP flag at least (Building against Android 2.3.3).

WakeLock screenLock = ((PowerManager)getSystemService(POWER_SERVICE)).newWakeLock(      PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG"); screenLock.acquire();  //later screenLock.release(); 
like image 117
undefined Avatar answered Oct 13 '22 01:10

undefined