我希望能够将两个警报注册到同一个BroadcastReceiver。但是,第一次警报永远不会被解雇。我怎样才能做到这一点?
Calendar now = Calendar.getInstance();
now.set(Calendar.SECOND, now.get(Calendar.SECOND) + 5);
long trigger1 = now.getTimeInMillis();
now.set(Calendar.SECOND, now.get(Calendar.SECOND) + 10);
long trigger2 = now.getTimeInMillis();
Intent startIntent = new Intent(AlarmStartReceiver.START_ALARM);
startIntent.putExtra(AlarmStartReceiver.EXTRA_ALARM_ID, 4);
PendingIntent startPIntent = PendingIntent.getBroadcast(context, 0, startIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent startIntent2 = new Intent(AlarmStartReceiver.START_ALARM);
startIntent2.putExtra(AlarmStartReceiver.EXTRA_ALARM_ID, 5);
PendingIntent startPIntent2 = PendingIntent.getBroadcast(context, 0, startIntent2, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarm.set(AlarmManager.RTC_WAKEUP, trigger1, startPIntent);
alarm.set(AlarmManager.RTC_WAKEUP, trigger2, startPIntent2);
只有第二个熄灭了。怎么能让它们都脱落?
编辑答案:将requestCode设置为唯一的。 PendingIntent.getBroadcast)方法的第二个参数 android pending intent notification problem
答案 0 :(得分:1)
将requestCode设置为唯一的。 PendingIntent.getBroadcast)方法的第二个参数android挂起意图通知问题
答案 1 :(得分:0)
您是否在为正在设置的每个闹钟寻找单独的通知事件?或者它必须与状态栏图标上显示的警报事件数相同的通知?
请看这篇文章,了解如何使用“setData()”来创建单独的警报。