Search code examples
androidalarmmanageralarmrepeat

I want to set repeating alarm that triggers every day at different time


I need the alarm to be triggered every day at sunrise. I get the sunrise time like this:"06:55"

Location location = new Location(latitude, longitude);
SunriseSunsetCalculator calculator = new SunriseSunsetCalculator(location, "GMT"+localTime);
String officialSunrise = calculator.getOfficialSunriseForDate(Calendar.getInstance());

That means every day the time to trigger will be different.

alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP, startmillis,intervalmillis, wakeUp); 

I would appreciate general guidance on what direction to go.


Solution

  • Instead of setting an alarm that will go off at a different time each day. You should set separate alarms each day. I recommend you do this by setting the next days alarm after an alarm goes off.