Zack
Zack

Reputation: 139

how to catch the alarm clock event on Android?

I want to build a playlist for the alarm clock in android. An app that will allow me to set the alarm for 7am weekday and it will play a different tune every time.

I have manged to set up a custom alarm programmatically with this code:

Intent i = new Intent(AlarmClock.ACTION_SET_ALARM);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra(AlarmClock.EXTRA_HOUR, hour);
i.putExtra(AlarmClock.EXTRA_MINUTES, minutes);
i.putExtra(AlarmClock.EXTRA_RINGTONE, "/path/to/file.mp3");
i.putExtra(AlarmClock.EXTRA_SKIP_UI, true);

I would like to register a call to this code so it will run after the user turned off the current alarm and it's possible snooze. Question is, how do I capture/override the event where the alarm is being triggered.

Also, would like to somehow store some extra key\value pairs in the alarm activity, so I would be able to read them once I catch the triggered alarm. Where should I save that data? The putExtra in my code here is related with the activity that sets a new alarm, not the activity that plays it.

Upvotes: 0

Views: 1962

Answers (1)

Katharina
Katharina

Reputation: 1642

use alarmmanager instead of a single intent. You can find a good example at this answer: https://stackoverflow.com/a/8801990/5052976

Upvotes: 2

Related Questions