AlarmManager Interval for Android

alarmmanager, android, notifications, statusbar

Solution

If I understand your requirement then you could try something like the following...

Calendar cal = Calendar.getInstance();
if (cal.get(Calendar.SECOND) >= 30)
    cal.add(Calendar.MINUTE, 1);
cal.set(Calendar.SECOND, 30);

// Do the Intent and PendingIntent stuff

am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 60 * 1000, pendingIntent);

Problem

This is the code I have so far ``` AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); setRepeatingAlarm(); public void setRepeatingAlarm() { Calendar cal = Calendar.getInstance(); cal.add(Calendar.SECOND, 10); Intent intent = new Intent(this, TimeAlarm.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), (15 * 1000), pendingIntent); } } ``` This is all I am trying to accomplish: The alarm will not turn on until 30 seconds past every minute. Once you clear it, it wont comes back on until 30 seconds past the next minute. So if I open the app, and it is 25 second past the minute, it will activate status bar notification 5 second later. But if it is 40 seconds past, I will have to wait 50 more seconds (into the next minute). I am not sure how to use the Calendar function to attain this?

Original source