-1

The app requirement is to trigger an alarm at any specified time and to perform the specified tasks at that particular time. To achieve this i have made use of AlarmManager. But it's not working in Android version 9.

I have used Alarm Manager which is working on Android version 7.0.

I made use of setInexactRepeating() method of AlarmManager.

I have tried to do it using below code :

AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);

I expect that the AlarmManager must be triggered at the specified time on Android version 9.

ADM
  • 20,406
  • 11
  • 52
  • 83

1 Answers1

0

This is what i did to fix the issue :

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
   
    am.set(AlarmManager.RTC_WAKEUP, stopTrackingAtMidnight, PendingIntent);

else
   
    am.setExact(AlarmManager.RTC_WAKEUP, stopTrackingAtMidnight, PendingIntent);

setExact() method worked for me !

olibiaz
  • 2,551
  • 4
  • 29
  • 31