我正在尝试使用广播接收器设置多个警报。我为两个警报设置了每 1 分 30 秒后的重复但是当我收到警报时,两者都在同一时间重复。
我这样做是这样的:
if(repeat.equals("No Repeat")){
bcr.CancelAlarm(getApplicationContext());
}
else if(repeat.equals("After 10 Minutes")) {
bcr.TenMintAlarm(getApplicationContext(), hour, minute, dueDate,task_note,Tasks_ID);
}
else if(repeat.equals("After 15 Minutes")){
bcr.FifteenMintAlarm(getApplicationContext(), hour, minute, dueDate,task_note,Tasks_ID);
}
else if(repeat.equals("After n Minutes")){
bcr.nMintAlarm(getApplicationContext(), hour, minute, dueDate,task_note,Tasks_ID);
}
广播接收器:
public void CancelAlarm(Context context)
{
Intent intent = new Intent(context, AlarmReceiver.class);
PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(sender);
}
public void TenMintAlarm(Context context,int hour,int minutes, String duedate,String task_note,int task_id)
{
AlarmManager Alarm1 = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmReceiver.class);
intent.putExtra("NOTE", note);
intent.putExtra("ID", task_id);
int mUniqID = task_id+2;
PendingIntent recurringAlarm = PendingIntent.getBroadcast(context, mUniqID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
System.out.println("mUniqID-----" +mUniqID);
Alarm1.setRepeating(AlarmManager.RTC_WAKEUP, _alarm, 1000 * 60, recurringAlarm);
}
public void FifteenMintAlarm(Context context, int hour,int minutes, String duedate, String task_note, int task_id)
{
AlarmManager Alarm2 = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, AlarmReceiver.class);
i.putExtra("NOTE", note);
i.putExtra("ID", task_id);
int uniqID = task_id+2;
System.out.println("mUniqID-----" +uniqID);
PendingIntent Alarm = PendingIntent.getBroadcast(context, uniqID, i, PendingIntent.FLAG_UPDATE_CURRENT);
Alarm2.setRepeating(AlarmManager.RTC_WAKEUP, _alarm, 1000 * 30, Alarm);
}
但是当收到警报时,它会同时重复,而不是我希望在 1 分钟和 30 秒后重复一个警报。任何建议都可能会有所帮助。谢谢。