I am trying to schedule a future notification using AlarmManager
from FirebaseMessagingService
when onMessageReceived()
.
Note: onMessageReceived()
gets triggered, and the same code works within an activity, but not within the service.
private void setReminder() {
Intent notificationIntent = new Intent(this, ReminderReceiver.class);
PendingIntent broadcast = PendingIntent.getBroadcast(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, 5);
alarmManager.setExact(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), broadcast);
}
Thanks!