我注册了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中),但是当时我更改了其他参数,我什至无法接收广播。
我以为有四种方法可以解决这个问题,但我只做了一个..
- 创建很多
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(){}}