我在broadcastreceiver
AndroidMainfest.xml
在我的应用程序中,一个功能是用户可以设置时间,此时应用程序将发送通知。我得到用户设置的参数,并使用alarmManager
来设置将在用户设置时发生的任务。
但我发现GOOGLE API说:
If there is already an alarm for this Intent scheduled (with the equality of two intents being defined by filterEquals(Intent)), then it will be removed and replaced by this one.
因此,如果我想设置两个或更多任务,Intent将被替换,最后我只能得到一个通知,这不是我想要的结果。
然后我发现意图是通过动作,数据,类型,类和类别来识别的, 但是我不能改变动作(意图的动作是在AndroidMainfest.xml中注册了intent-filter的动作),但是当我更改其他参数时,我甚至无法接收广播。
我认为有四种方法可以解决这个问题,但我只做了一个..
broadcastreceiver
并在其中注册
AndroidMainfest.xml
,这样我可以改变意图
行动broadcastreceiver
,但我没有
让它任何帮助将不胜感激!!
Intent intent = new Intent("aaa"); //there was a broadcastreceiver's intent-filter "aaa"
intent.putExtra("title", title);
intent.putExtra("table", "计划");
PendingIntent pi = PendingIntent.getBroadcast(Alarm.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager)getSystemService(Alarm.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+time, pi);
代码位于onClickListener {onClick(){}}
答案 0 :(得分:0)
您可以使用日历对象并在任何所需的时间设置闹钟,而不是不允许您设置重复闹钟的广播。一旦警报开启,您的代码将自动运行,并且您已设置警报的次数。 您还可以获得以下教程的帮助。我相信它会以某种方式帮助你。
http://blog.mikesir87.io/2013/04/android-creating-an-alarm-with-alarmmanager/