无法在不同时间多次安排通知, 正在调度的通知是最后一个未注明日期的时间,只有下面的代码包含两个方法,这两个方法都有自己的警报管理器,但即使安排了两个通知,但只有一个通知出现,并且应该在最后一个时间安排
public void monday_sch(){
Intent intent = new Intent(this, MyBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this.getApplicationContext(), 30000, intent, 0);
String stat=smonday.getText().toString();
try {
SimpleDateFormat format = new SimpleDateFormat("HH:mm");
Date d1 = null;
d1 = format.parse(stat);
Calendar cal = Calendar.getInstance();
cal.setTime(d1);
cal.add(Calendar.MINUTE, -5);
String oneHourBack = String.valueOf(cal.getTime());
String customiese=oneHourBack.substring(10, oneHourBack.length() - 18);
Toast.makeText(getApplication(),customiese,Toast.LENGTH_LONG).show();
StringTokenizer st = new StringTokenizer(customiese.trim(), ":");
hour_mon = Integer.valueOf(st.nextToken());
min_mon = Integer.valueOf(st.nextToken());
}catch (Exception kk){
}
if(monday==true)
{
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_WEEK,6);
cal.set(Calendar.HOUR_OF_DAY,hour_mon);
cal.set(Calendar.MINUTE, min_mon);
cal.set(Calendar.SECOND, 0);
alarmManager_mon = (AlarmManager) getSystemService(ALARM_SERVICE);
/*alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
+ (i * 1000), (i * 1000), pendingIntent);*/
alarmManager_mon.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlarmManager.INTERVAL_DAY * 7, pendingIntent);
}
else if(monday==false){
alarmManager_mon = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager_mon.cancel(pendingIntent);
}
}
public void sunday_sch(){
Intent intent = new Intent(this, MyBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this.getApplicationContext(), 30000, intent, 0);
String stat=ssunday.getText().toString();
try {
SimpleDateFormat format = new SimpleDateFormat("HH:mm");
Date d1 = null;
d1 = format.parse(stat);
Calendar cal = Calendar.getInstance();
cal.setTime(d1);
cal.add(Calendar.MINUTE, -5);
String oneHourBack = String.valueOf(cal.getTime());
String customiese=oneHourBack.substring(10, oneHourBack.length() - 18);
Toast.makeText(getApplication(),customiese,Toast.LENGTH_LONG).show();
StringTokenizer st = new StringTokenizer(customiese.trim(), ":");
hour_sun = Integer.valueOf(st.nextToken());
min_sun = Integer.valueOf(st.nextToken());
}catch (Exception kk){}
if(sunday==true)
{
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_WEEK,6);
cal.set(Calendar.HOUR_OF_DAY,hour_sun);
cal.set(Calendar.MINUTE, min_sun);
cal.set(Calendar.SECOND, 0);
alarmManager_sun = (AlarmManager) getSystemService(ALARM_SERVICE);
/*alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
+ (i * 1000), (i * 1000), pendingIntent);*/
alarmManager_sun.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlarmManager.INTERVAL_DAY * 7, pendingIntent);
}
else if(sunday==false){
alarmManager_sun = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager_sun.cancel(pendingIntent);
}
}
`
答案 0 :(得分:2)
当您为不同时间多次设置计划通知时
然后使用:PendingIntent unique_id
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this.getApplicationContext(), unique_id, intent, 0);
unique_id
每次都设置不同。