1

Any ideas why my alarm manager will not run? I have been fiddling around for hours and one of them is running but the other isn't and I can't find a solution.

Calendar cur_cal = new GregorianCalendar();
cur_cal.setTimeInMillis(System.currentTimeMillis());//set the current time and date for this calendar

Calendar cal = new GregorianCalendar();
cal.add(Calendar.DAY_OF_YEAR, cur_cal.get(Calendar.DAY_OF_YEAR));
cal.set(Calendar.HOUR_OF_DAY, startHours);
cal.set(Calendar.MINUTE, startMinutes);
cal.set(Calendar.DATE, cur_cal.get(Calendar.DATE));
cal.set(Calendar.MONTH, cur_cal.get(Calendar.MONTH));

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent intent = new Intent(WelcomeScreen.this, DNDAlarm.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(WelcomeScreen.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 86400000, pendingIntent);
Nikos Hidalgo
  • 3,666
  • 9
  • 25
  • 39
Coder101
  • 17
  • 2

1 Answers1

0

You must declare the Broadcast receiver in the manifest file, here's an example from the docs:

<receiver android:name=".MyBroadcastReceiver"  android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"/>
        <action android:name="android.intent.action.INPUT_METHOD_CHANGED" />
    </intent-filter>
</receiver>
Curious Mind
  • 659
  • 10
  • 26