如果系统时间改变为过去,则重复警报不起作用

时间:2017-09-03 07:12:15

标签: android alarmmanager alarm repeatingalarm

我是Android的新手,在设置重复闹钟时遇到问题。该应用程序是这样的:用户使用时间戳选择时间,并选择几天来设置警报。我使用此代码来实现此任务:

for(int i=0; i < alarm.getDaysOfTheWeek().size(); i++){

        // here is a switch block to assign daysUntilAlarm1 
        //to a particular day from the list of selected days, like 
        //daysUntilAlarm1 = Calendar.SUNDAY;


        calendar.set(Calendar.DAY_OF_WEEK, daysUntilAlarm1);

        calendar.set(Calendar.HOUR_OF_DAY, alarm.getHour()); // hour picked by user
        calendar.set(Calendar.MINUTE, alarm.getMinute());


        pendingIntent = PendingIntent.getBroadcast(AlarmManagerActivity.this, i, intentToAlarmReceiver, 0);
        pendingIntents.add(pendingIntent);


        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 7 * 24 * 60 * 60 * 1000, pendingIntent);

问题是当我测试警报时,我将系统时间更改为下一个警报日。一切正常。但是,当我将系统时间更改为过去时,就像上周一样,警报无法正常工作。因此,如果用户必须将设备的时间更改为过去,则该应用程序将无法运行。有人可以帮帮我吗?

0 个答案:

没有答案