我正在设置警报应用程序,设置多天警报,即重复警报。我的Android警报应用程序视图如下,
我为此完成了代码,
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent alarmIntent = new Intent(ALARM_ACTION_NAME);
alarmIntent.putExtra("AlarmID", m_alarmId);
PendingIntent alarmPI = PendingIntent.getBroadcast(this, m_alarmId, alarmIntent, 0);
//listofred is a ArrayList of int items.contains int valye for selected days...for My Example listofred:3,4,5,7
for (int i = 0; i < listOfred.size(); i++) {
// for alarm ...
calNow = Calendar.getInstance();
calSet = (Calendar) calNow.clone();
int day = calSet.get(Calendar.DAY_OF_WEEK); //current day...for example.13 dec 2014 - sat so, day = 7
calSet.set(Calendar.DAY_OF_WEEK, listOfred.get(i));
calSet.set(Calendar.HOUR_OF_DAY, time_picker.getCurrentHour());
calSet.set(Calendar.MINUTE, time_picker.getCurrentMinute());
calSet.set(Calendar.SECOND, 0);
calSet.set(Calendar.MILLISECOND, 0);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
calSet.getTimeInMillis(), (DateUtils.DAY_IN_MILLIS)*7,
alarmPI);
//parameter long intervalMillis.....(DateUtils.DAY_IN_MILLIS)*7 so that it will repeat after each 7 days...
}
我的问题是当我运行此代码时,每次为Arraylist中的最后一个对象设置警报时,它将仅为星期六(,即listofred Arraylist中的最后一个对象)设置重复警报。
答案 0 :(得分:1)
我知道回答这个问题已经很晚了,但并不是因为每个警报事件都传递了相同的待处理意图。 也许这可能有所帮助。
PendingIntent alarmPI = PendingIntent.getBroadcast(this, m_alarmId, alarmIntent, PendingIntent.FLAG_ONE_SHOT);