Question

I am trying to register an alarm with the android alarm manager and cannot seem to figure out why the the alarms aren't firing. I've looked at many examples online and my code seems to be doing the same thing that they suggest but still no success. I am running it on android 4.4 (KitKat)

Here is how I set the alarm:

public void registerAlarm(Context context, int hour, int minute) {
    AlarmManager alarmMgr = (AlarmManager) context.getSystemService(
            Context.ALARM_SERVICE);
    Intent intent = new Intent(context, AlarmReciever.class);
    PendingIntent alarmIntent = PendingIntent.getBroadcast(context,
            0, intent, 0);
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.SECOND, 0);
    alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 10000,
            alarmIntent);
}

and here is how my receiver for it:

package com.alarm.alarm;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class AlarmReciever extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context, "recieved", Toast.LENGTH_LONG).show();
   }
}

Here is how I declare my receiver in the manifest

<receiver android:name="com.alarm.alarm.AlarmReceiver">
</receiver>

and here is the SET ALARM permission

<uses-permission android:name="com.alarm.permission.SET_ALARM"/>

I have been stuck on this issue for hours. any clarification as to what i might be doing wrong would be greatly appreciated!

Was it helpful?

Solution

You have a typo in Broadcast class name, it should be AlarmReceiver instead of AlarmReciever per your Manifest

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top