Skip to content Skip to sidebar Skip to footer

Android Alarmmanager.set(...): Notification Never Received When Battery Low

I'm attempting to use AlarmManager to schedule a delayed check in my app. (Specifically, N minutes after a user approaches a location, I want to check whether they're still there,

Solution 1:

It turns out that this is related to the use of the real-time clock.

Although I could not find the documentation it quotes (it's not in AlarmManager), this StackOverflow answer suggests that AlarmManager.RTC_WAKEUP alarms do not trigger if the phone is in power-saving mode. AlarmManager.ELAPSED_REALTIME_WAKEUP alarms do not seem to suffer this problem, so I was able to fix the issue by switching to:

IntentgeofenceIntent=newIntent(context, GeofenceReceiver.class)
// ...intent contents not important...PendingIntentpi= PendingIntent.getBroadcast(context, 0, geofenceIntent, PendingIntent.FLAG_UPDATE_CURRENT);

longmillis= SystemClock.elapsedRealtime() + 1000 * getGeofenceDelaySeconds();
AlarmManageralarmManager= (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, millis, pi);

Post a Comment for "Android Alarmmanager.set(...): Notification Never Received When Battery Low"