0

我注册了broadcastreceiver一个AndroidMainfest.xml

在我的应用程序中,一个功能是用户可以设置时间,此时应用程序将发送通知。我得到参数 User set ,并用于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 将被替换,最后我只能得到一个通知,这不是我想要的结果。

然后我发现intent是通过action、data、type、class和categories来识别的,但是我不能改变action(intent的action是intent-filter的action注册在AndroidMainfest.xml中),但是当时我更改了其他参数,我什至无法接收广播。

我以为有四种方法可以解决这个问题,但我只做了一个..

  1. 创建很多broadcastreceiver并在其中注册它们 AndroidMainfest.xml,这样我就可以改变意图的动作
  2. 在程序中注册broadcastreceiver,但我没有成功
  3. 使用服务+定时器类..
  4. 在不改变行动的情况下使两个意图不同。

任何帮助将不胜感激!!

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(){}}

4

1 回答 1

0

除了不允许您设置重复闹钟的广播之外,您还可以使用日历对象并在任何需要的时间设置闹钟。一旦警报打开,您的代码将自动运行,并且您设置了警报的次数。您还可以参考以下教程。我相信它会以某种方式帮助你。

http://blog.mikesir87.io/2013/04/android-creating-an-alarm-with-alarmmanager/

于 2012-12-12T05:14:49.330 回答