0

i want to set an alarm that goes off at a certain time and repeats once a day. But if the time i set is already in the past for today, i want it to fire on the next day, not right now.

 public void testAlarmButton() {

    AlarmManager alarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(getContext(), AlertReceiver.class);
    PendingIntent alarmIntent = PendingIntent.getBroadcast(getContext(), 0, intent, 0);

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, 18);
    calendar.set(Calendar.MINUTE, 20); //goes off immediatly if it is later than 18:20

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

}

Edit: This question is not a duplicate of the suggested one, because this is about repeating alarms, not about a single alarm.

Florian Walther
  • 6,237
  • 5
  • 46
  • 104
  • This question is not a duplicated, since the other one is about single time alarms. Can you please unlock it again. – Florian Walther Aug 27 '17 at 18:57
  • The solution is exactly the same. You need to push the starting time to tomorrow. It's doesn't matter what kind of alarm it is. They all behave the same way with respect to the start time. – Mike M. Aug 28 '17 at 01:44
  • You are right, sorry. – Florian Walther Aug 28 '17 at 01:44
  • No worries. For future reference, if you use the @name of the user who closed your question, they'll get a notification in their inbox, just like if they'd commented. Otherwise, we don't know if you've edited your question, or left a comment, unless we just happen to come back to check. Cheers! – Mike M. Aug 28 '17 at 01:49

0 Answers0