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.