setAlarmClock not firing alarms after 15 days of correct work

297 Views Asked by At

I'm using the AlarmManager.setAlarmClock() to remind my app users to take their medicine.

Today (after 15 days of correct work) setAlarmClock() did not fire an alarm to notify my users.

How do i schedule?

        for (Reminder reminder : reminderArrayList) {
        if(reminder.isActive()){
            GregorianCalendar cal = new GregorianCalendar();
            cal.set(GregorianCalendar.HOUR_OF_DAY, reminder.getHour());
            cal.set(GregorianCalendar.MINUTE, reminder.getMinute());
            cal.set(GregorianCalendar.SECOND, 0);
            while(cal.before(Calendar.getInstance())){
                cal.add(GregorianCalendar.DAY_OF_YEAR, getDaysFromIntervall(reminder.getIntervall()));
            }
            Intent intent = new Intent(context, AlarmReceiver.class);
            intent.putExtra("reminder_id", reminder.getId());

            PendingIntent pi = PendingIntent.getBroadcast(context, reminder.getCode(), intent, PendingIntent.FLAG_CANCEL_CURRENT);

            AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
            am.setAlarmClock(new AlarmManager.AlarmClockInfo(cal.getTimeInMillis(), pi), pi);

        }
    }

The problem occurred on Galaxy S7 edge with Android 8.0.0

How can I ensure that my alarms will fire?

Help would be appreciate.

Thanks in advance.

Patrick

0

There are 0 best solutions below