Garbit
Garbit

Reputation: 6056

Android - How to detect if alarm has been set (alarmmanager)

I've got a 'welcome' screen which downloads the times that the alarms should go off, however each time the user lands on the screen a new alarm is set

this of course causes multiple alarms

is there any way you can detect if one has been set for today?

thanks for your help in advance

Andy

Upvotes: 0

Views: 1554

Answers (2)

jainal
jainal

Reputation: 3021

If you set alarm with same pending intent then previous alarm will be cancelled and reset again.if you want to cancel any alarm then you can cancel that alarm by alarmManager.cancel(operation). If you set an alarm like this.

  PendingIntent sender = PendingIntent.getBroadcast(MyAlarm.this,0,intent, 0);
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
            alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (5 * 1000), sender);

Then you cancel that alarm by the following way.

 alarmManager.cancel(sender);

Upvotes: 6

Nikolay Elenkov
Nikolay Elenkov

Reputation: 52956

Not via the Android API. You have to save the times yourself to SharedPreferences or some file if you want to look them up later.

Upvotes: 2

Related Questions