我的重复闹钟在星期天第一次开始,无论时间(如果过去)这里都是问题,在下周日警报重复正确,我想从下一个星期日开始闹钟..这是我的代码:
AlarmManager alarmMgr = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(activity, Alarm.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(activity, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calendarStart = Calendar.getInstance();
calendarStart.set(Calendar.DAY_OF_WEEK, 1 );
calendarStart.set(Calendar.HOUR_OF_DAY,8);
calendarStart.set(Calendar.YEAR,calendarStart.get(Calendar.YEAR));
calendarStart.set(Calendar.MINUTE, 0);
calendarStart.set(Calendar.SECOND, 0);
Toast.makeText(activity, calendarStart.getTime()+"",Toast.LENGTH_LONG).show();
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendarStart.getTimeInMillis() ,24*60*60*1000, pendingIntent);
答案 0 :(得分:1)
我的重复闹钟在星期天第一次开始,无论何时(如果过去)
检查过去是否calendarStart
以及是否添加了7天:
if(calendarStart.compareTo(Calendar.getInstance()) < 0) {
// calendarStart is in the past, use next Sunday
calendarStart.add(Calendar.DAY_OF_YEAR, 7);
}
Toast.makeText(activity, calendarStart.getTime()+"",Toast.LENGTH_LONG).show();