Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to unlock the screen when BroadcastReceiver is called?

As you can guess, i register an alarm by AlarmManager. And the BroadcastReceiver will be called correctly. But when it called, my phone screen is still locked. I notice the default AlarmClock application is not like this. So my question is, how to unlock the screen when the BroadcastReceiver is called ? (Unlock the screen can make the user to operate my Activity directly) Thanks in advance.

like image 533
kevin lynx Avatar asked Dec 04 '10 07:12

kevin lynx


1 Answers

The source code for the alarm clock is in the Android source code. AlarmClock is gone, but has been replaced by DeskClock. Source code is here. I glanced over the code real quick, and their receiver seems to use the KeyguardManager. Check out the docs, that seems to be what you want.

EDIT: I'll add your findings here. This code should do:

final Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
              | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); 
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
              | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
like image 173
EboMike Avatar answered Oct 21 '22 04:10

EboMike