Question

I have defined my Android alarm and BroadcastReceiver as follows. My hope was that I want the alarm to go off two minutes later and every 15 minutes subsequently. This does not seem to be happening. Why is this?

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) + 2);
PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(getApplicationContext(), DailyNotificationReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_FIFTEEN_MINUTES, pi);


public class DailyNotificationReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("received", "received");
        }
}
Was it helpful?

Solution

As discussed in the comments, the BroadcastReceiver was not registered.

Please register the BroadcastReceiver in the manifest

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