0

In my Android application, I need to show notification at some specific time. I a setting the alarm as below, but the notification is not shown on exact time. Instead it is shown at random time after the alarm set time. Below is my code...

 AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, uniqueCode, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT);

    if (time != 0) {
        int currentApiVersion = android.os.Build.VERSION.SDK_INT;
        if (currentApiVersion <= 18) {
            Log.d(TAG, "API <= 18");
            alarmManager.set(AlarmManager.RTC, time, pendingIntent);
        } else {
            Log.d(TAG, "I am using Nexus 5 with lollipop and it comes here"); 
            alarmManager.setExact(AlarmManager.RTC, time, pendingIntent);
        }

As I am using Nexus 5 with lollipop, and setting the alarm using setExact() method. Still it is not executing on time...

Please help!

Sam
  • 2,972
  • 6
  • 34
  • 62

1 Answers1

0

Despite it's name, setExact does not trigger an alarm at the exact specified time, for battery saving reasons as far as I know. To really have a precise alarm, use AlarmManager.setAlarmClock instead.

Zelig63
  • 1,592
  • 1
  • 23
  • 40