0

I'm trying to read the time of the next alarm, but I keep getting the following error code on the console:

E/Handler: Failed to handle callback; interface not implemented, callback:android.view.View$PerformClick@40e45bd8
    java.lang.NoSuchMethodError: android.app.AlarmManager.getNextAlarmClock

Setting the alarm works fine, the alarm then triggers at the specified time, it's just that I need to get the time when it will trigger again to use it elsewhere.

The relevant code is below. In case you wonder: I'm now trying to read the alarm immediately after setting it order to debug.

            // Copy data from the time picker to the calendar
            calendar.set(Calendar.HOUR_OF_DAY, hours);
            calendar.set(Calendar.MINUTE, minutes);

            // Create a pending intent that delays the intent until the specified time
            pending_intent = PendingIntent.getBroadcast(MainActivity.this, 0,
                    alarm_intent, PendingIntent.FLAG_UPDATE_CURRENT);

            // Set the alarm manager
            alarm_manager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pending_intent);

            // Read the alarm setting
            long nextLong= alarm_manager.getNextAlarmClock().getTriggerTime();
            String nextAlarm = Long.toString(nextLong);
            Log.e("Next Alarm:", nextAlarm);
            Toast.makeText(context, nextAlarm, Toast.LENGTH_LONG).show();

Any ideas? Thanks in advance.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
kxtronic
  • 331
  • 5
  • 16
  • That method wasn't introduced until API level 21: https://developer.android.com/reference/android/app/AlarmManager.html#getNextAlarmClock(). Are you testing on a prior version? Also, you'll note that it only works for alarms set with `setAlarmClock()`. – Mike M. May 13 '18 at 19:35
  • Hi Mike, indeed I'm writing an app for old hardware, so I would like to go as low as 4.0.03 - API 15. Is there a way to read the alarm setting in that release? Tks, Philip – kxtronic May 13 '18 at 19:41
  • For debugging purposes, you can use adb: https://stackoverflow.com/q/28742884. – Mike M. May 13 '18 at 19:45

0 Answers0