android - Turning on screen from receiver/service -


i app able turn screen on , display app. let's i'm setting alarm , every hour want app displayed 2 mins before device naturally sleeps.

i see wakelock (full_lock) , keyguardmanager deprecated.

i have created wakefulbroadcastreceiver , service , these working.

@override protected void onhandleintent(intent intent) {     // need show screen here!      (int i=0; i<5; i++) {         log.i("simplewakefulreceiver", "running service " + (i + 1)                 + "/5 @ " + systemclock.elapsedrealtime());         try {             thread.sleep(5000);         } catch (interruptedexception e) {         }     }     log.i("simplewakefulreceiver", "completed service @ " +            systemclock.elapsedrealtime());     simplewakefulreceiver.completewakefulintent(intent); } 

how programmatically turn on screen, past lock , display activity intentservice ?

thanks

you can use code turn screen on.

lock = ((keyguardmanager) getsystemservice(activity.keyguard_service)).newkeyguardlock(keyguard_service); powermanager = ((powermanager) getsystemservice(context.power_service)); wake = powermanager.newwakelock(powermanager.full_wake_lock | powermanager.acquire_causes_wakeup, "tag");  lock.disablekeyguard(); wake.acquire();            getwindow().addflags(windowmanager.layoutparams.flag_show_when_locked                 | windowmanager.layoutparams.flag_dismiss_keyguard                 | windowmanager.layoutparams.flag_keep_screen_on                 | windowmanager.layoutparams.flag_turn_screen_on                 | windowmanager.layoutparams.flag_allow_lock_while_screen_on); 

you need following permission in androidmanifest.xml file:

<uses-permission android:name="android.permission.wake_lock" /> <uses-permission android:name="android.permission.disable_keyguard" /> 

edit (use one, nothing deprecated):
there 1 more alternative doing this, need launch activity, in activity oncreate() need add flags window. example:

   @override     protected void oncreate(bundle savedinstancestate) {       getwindow().addflags(windowmanager.layoutparams.flag_show_when_locked | windowmanager.layoutparams.flag_dismiss_keyguard | windowmanager.layoutparams.flag_keep_screen_on | windowmanager.layoutparams.flag_turn_screen_on | windowmanager.layoutparams.flag_allow_lock_while_screen_on);` } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -