我有这个目标设定应用程序,其中在应用程序中设置的目标的每个活动都设置了警报时间和日期。
例如:
目标1:A
Activity a1: nana
Deadline: 11/5/2015
Alarm Time: 9:00 am
目标2:B
Activity b1: hehe
Deadline: 11/5/2015
Alarm Time: 9:00 am
只有其中一人被解雇。我尝试在每个活动闹钟时间上给它们设置不同的毫秒数。但它仍然是一样的。我希望他们同时被解雇。我尝试了其他来源,他们建议使用setExact(),但我不能使用该功能导致它仅适用于API 19及更高版本。我的API是17.当我设置不同时间但同一日期的警报时,没有问题。
这是我的代码:
首先,我将闹钟时间设置在TABLE_ACTIVITIES中的活动上。
public void setAlarm(){
Activities act = dbhandler.getActivity(actid);
// give them random millisecond
int min = 1;
int max = 1000;
Random r = new Random();
m = r.nextInt(max - min + 1) + min;
MessageTo.message(SetNotifyActivity.this,Integer.toString(m));
//the second is 0
dbhandler.updateActivityAlarm(hour,minute,0,m,goal_id,actid);
}
然后在用户在每个目标中进行的所有活动中设置所有警报
public void setAlarms(){
List<Activities> allActs = dbhandler.getAllActivitiesByGoal(goal_id);
for (final Activities act : allActs) {
//for alarm
//Create an offset from the current time in which the alarm will go off.
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
cal.set(Calendar.DATE, Integer.parseInt(act.getEDay())); //1-31
cal.set(Calendar.MONTH, Integer.parseInt(act.getEMonth()) - 1); //first month is 0!!! January is zero!!!
cal.set(Calendar.YEAR, Integer.parseInt(act.getEYear()));//year...
cal.set(Calendar.HOUR_OF_DAY, act.getHour());
cal.set(Calendar.MINUTE, act.getMinute());
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, act.getMillisecond());
//MessageTo.message(SetNotifyActivity.this, hour+":"+minute+" "+format);
//assigned a unique id to notifications
//Create a new PendingIntent and add it to the AlarmManager
Intent intent3 = new Intent(this, ViewTasksActivity.class);
intent3.putExtra("goalid", Integer.toString(goal_id));
intent3.putExtra("activityId", Integer.toString(act.getActId()));
intent3.putExtra("activityName", act.getActivityName());
intent3.putExtra("show", "true");
PendingIntent pendingIntent = PendingIntent.getActivity(this,
act.getActId(), intent3, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am =
(AlarmManager) getSystemService(Activity.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
pendingIntent);
}
}