简体   繁体   中英

AlarmManager - get next scheduled time of an repeating alarm

I'm setting a repeating alarm with alarmManager.setRepeating(...); and I now want to find out, what the next scheduled time of this alarm is.

How can I do that?

I can get the PendingIntent from the AlarmManager , but I don't know, how to find out, when the alarm manager will fire it's next event for my Intent...

Question:

Is it possible (and if yes, how) to get the next time of an scheduled alarm?

PS: I'm not asking for simple maths, I CAN calculate it on my own, I'm just curious, if I can get the information from somewhere else...

Follow the example

public static int mailSyncInterval = 10; // in minute

Intent alarmIntent = new Intent(LoginActivity.this, MailSyncReceiver.class);
            PendingIntent sender = PendingIntent.getBroadcast(LoginActivity.this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            long firstTime = SystemClock.elapsedRealtime();
            AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
            am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, 1000 * 60 * mailSyncInterval, sender);

Receiver will call after every 10 min from current time in device.

To get Next Schedule time

MailSyncReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
     long nextTime = System.currentTimeMillis() + (1000 * 60 * mailSyncInterval);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM