android - Pausing Service during alarm, resuming it afterwards -


so have service want able listen alarms , temporarily shut down/pause whilst alarm rings, , resume afterwards. service inflates view using windowmanager on top of screen - it's lock screen app.. such, it's on top of else..

this easy enough implement incoming calls using phonestatelistener haven't seen handy alarms - guess implement alarmmanager.onalarmlistener shuts service down once alarm rings, i'm not sure of how turn on again afterwards.

thankful help!

finally figured out!

you can time of next alarm so:

  alarmmanager alarmmanager = (alarmmanager) getsystemservice(alarm_service);   alarmmanager.getnextalarmclock().gettriggertime() 

so add service oncreate method:

alarmmanager alarmmanager = (alarmmanager) getsystemservice(alarm_service);         if (alarmmanager.getnextalarmclock() != null) {             uihandler.postattime(new runnable() {                 @override                 public void run() {                     stopself();                 }             }, alarmmanager.getnextalarmclock().gettriggertime());         } 

essentially time of next alarm in milliseconds, post runnable @ time of next alarm.

i believe work on api 21+


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -