From my trials with alarmmanager I've noticed it doesn't handle large day values for the internal in setrepeating. So what would be the best approach to send a notification every 30/60/90 days and the like? Is there a way to do this with alarmmanager or do I need to use a different approach?
Asked
Active
Viewed 1,159 times
3 Answers
0
Use alarm manager
and put your notification in NotifyService
class
Intent myIntent = new Intent(Current.this , NotifyService.class);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
pendingIntent = PendingIntent.getService(ThisApp.this, 0, myIntent, 0);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 12);
calendar.set(Calendar.MINUTE, 00);
calendar.set(Calendar.SECOND, 00);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 24*60*60*1000 , pendingIntent); //set repeating every 24 hours
0
All you need is a specific repeat interval as per your need, like
60 days = 60*24*60*60*1000 (time in millis)
Plus, one important thing to keep in mind. as you are trying to set alarm for such long repeat interval, with android its natural that device will undergo shut down or reboot. Under this circumstances, Alarmanager clears all the alarm which were set before device was rebooted, hence you need to detect when device reboot and set all the required alarm again.
RobinF has already posted code for setting the alarm, you can refer that.

Techfist
- 4,314
- 6
- 22
- 32
0
Try pending Intent with alarm manager and pass time as 1*24*60*60*1000(time for 1 day)

Barun
- 312
- 3
- 16