java - BroadcastReceiver onReceive() never invoked -
i trying invoke broadcastreceiver
resides inner class. since it's inside class need register receiver programmatically. can see alarm works first time since device exits doze when triggered, can't re-register alarm since onreceive() method never triggers when alarm goes off.
i have tried several combinations , examples found online can't seem work.
my guess need add more intentfilter
in order broadcast.
relevant code:
public class analogwatchface extends canvaswatchfaceservice { private class engine extends canvaswatchfaceservice.engine { @override public void oncreate(surfaceholder holder) { setbufferclearalarm(); } private void setbufferclearalarm() { alarm = new bufferalarmreciever(); intentfilter filter = new intentfilter(); filter.addaction("0"); analogwatchface.this.registerreceiver(alarm, filter); alarm.setalarm(analogwatchface.this); } public class bufferalarmreciever extends broadcastreceiver { private alarmmanager alarmmanager; private pendingintent alarmintent; @override public void onreceive(context context, intent intent) { setalarm(context); } //sets alarm public void setalarm(context context) { cancelalarm(context); alarmmanager = (alarmmanager) context.getsystemservice(context.alarm_service); intent intent = new intent(context, bufferalarmreciever.class); intent.setaction("0"); alarmintent = pendingintent.getbroadcast(context, 0, intent, 0); log.d(tag, "setting alarm"); alarmmanager.setalarmclock(new alarmmanager.alarmclockinfo(system.currenttimemillis()+60000,alarmintent),alarmintent); } //cancels public void cancelalarm(context context) { alarmmanager = (alarmmanager) context.getsystemservice(context.alarm_service); intent intent = new intent(context, bufferalarmreciever.class); intent.setaction("0"); alarmintent = pendingintent.getbroadcast(context, 0, intent, 0); log.d(tag, "cancelling alarm"); alarmmanager.cancel(alarmintent); } } } }
Comments
Post a Comment