报警时间过去后如何避免报警触发?

M V*_*esh 2 android alarmmanager android-pendingintent repeatingalarm

我已安排每天上午10点触发警报.

我在星期一上午12点设置此闹钟.

如果闹钟时间过去,则会立即触发闹钟.

但是根据我的要求,我不想立即触发.我可以在第二天上午10点触发.

下面是我当前设置闹钟的代码:

Calendar activeModeTime = Calendar.getInstance();
    // activeModeTime.setTimeZone(TimeZone.getTimeZone(Constants.TIME_ZONE));
    activeModeTime.set(Calendar.HOUR_OF_DAY,
            mSharedPrefManager.getActiveStartHourPref());
    activeModeTime.set(Calendar.MINUTE,
            Constants.DEFAULT_ACTIVE_START_MINUTE);
    activeModeTime.set(Calendar.SECOND,
            Constants.ALL_START_END_DEFAULT_SECOND);

    mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
            activeModeTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
            getActiveModeAlarmPendingIntent());
Run Code Online (Sandbox Code Playgroud)

我该如何实现这一目标.

rah*_*cho 5

检查您设置的时间是否已经过去,如果是,那么将24小时添加到您的触发时间.

if(activeModeTime < System.currentTimeMillis()){
    activeModeTime += AlarmManager.INTERVAL_DAY;
}
Run Code Online (Sandbox Code Playgroud)