Hi, I am working on an alarm app. I followed the Android AlarmController tutorial word for word with only some minor changes. For some reason my Broadcast Receiver's onReceive() method is not being called when the alarm goes off. Here's the code:
// the callback received when the user "sets" the time in the dialog
private TimePickerDialog.OnTimeSetListener mTimeSetListener =
new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
time.set( Calendar.HOUR_OF_DAY, hourOfDay );
time.set( Calendar.MINUTE, minute );
// Tell user alarm was set
String timeSetTo = "Alarm Set: " + time.get( Calendar.HOUR_OF_DAY ) + ":" + time.get( Calendar.MINUTE ) + " " + time.get( Calendar.AM_PM );
if( toast != null )
toast.cancel();
toast = Toast.makeText( AlarmUI.this, "L" + timeSetTo, Toast.LENGTH_LONG );
toast.show();
// When the alarm goes off we want to send an Intent to our Broadcast Receiver (AlarmAction),
// so set an Intent between the AlarmUI and the AlarmAction
Intent intent = new Intent( AlarmUI.this, AlarmAction.class );
// Create an IntentSender to have the intent executed as a broadcast later when alarm goes off.
PendingIntent sender = PendingIntent.getBroadcast( AlarmUI.this, 0, intent, 0 );
/** Schedule the alarm */
// To get any service we use getSystemService( Service Name )
AlarmManager alarmManager = ( AlarmManager ) getSystemService( ALARM_SERVICE );
/* Finally, we set the alarm to the desired time! WOOHOO! */
alarmManager.set( AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), sender );
}
};
Any ideas? Thank you in advance.