我的目标是为 eventsDb.getFavouriteEvents()
中的每个事件触发警报,但每次只触发一个警报。
在我看来,这可能是由于设置PendingIntent.FLAG_UPDATE_CURRENT
引起的,但是我需要这个标志来有 Intent 地发布附加内容。有什么方法可以不设置此标志并仍然有意地发布附加内容吗?
我将 PendinIntents
存储在集合 (pendingIntents
) 中,因为我要在此 的
类。onDestroy()
中取消它们服务
这是来自onCreate()
的代码:
for(Event event : eventsDB.getFavouriteEvents()) {
Intent intent = new Intent(AlarmReciever.ONCOMING_EVENT);
intent.putExtra(Event.TITLE, event.getTitle());
PendingIntent pendingIntent = PendingIntent.getBroadcast(EventAlarmService.this, 0, intent,
Intent.FLAG_GRANT_READ_URI_PERMISSION | PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.set(AlarmManager.RTC_WAKEUP, event.getTime(), pendingIntent);
pendingIntents.add(pendingIntent);
}
感谢您的帮助!
最佳答案
如果它们共享相同的代码,PendingIntent 将在发送时被覆盖。更改每个发送 Intent 的代码应该可以纠正此问题。
关于android - 设置多个警报时仅触发一个警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10422375/