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
Post a Comment