How to wake up the screen in android

Hi, I am making an Alarm app. When the alarm time comes, I show the user a dialog. But the problem is that I want to get a lock after a dialog box appears. just like when just received sms, the screen just wakes up.

I tried this one but it doesn't work

public class Alarm extends Activity{ PowerManager pm; WakeLock wl; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); pm = (PowerManager) getSystemService(POWER_SERVICE); wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "FlashActivity"); wl.acquire() showAlarmDialog(); } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); wl.release(); } } 

I also added permission to wakelock. Help will be announced :-)

+7
source share
3 answers

I managed to turn on the screen like this:

 wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG"); wl.acquire(); 

Hope this help. This worked for me though :-) Cheers

+3
source

You can acquire a wake lock in two ways.

 wl.acquire(); or wl.acquire(timeout) 

Try something similar in onResume ():

 PowerManager pm; WakeLock wl; pm = (PowerManager) getSystemService(POWER_SERVICE); wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "FlashActivity"); wl.acquire(); Or wl.acquire(timeout) 

And you are realeasing in onPause (). It's good.

+3
source

You can add several flags to your activity to unlock and launch the screen when your activity starts.

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.my_activity); getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); } 
+1
source

All Articles