|
32 | 32 |
|
33 | 33 | import androidx.annotation.NonNull; |
34 | 34 | import androidx.annotation.Nullable; |
| 35 | +import androidx.core.app.AlarmManagerCompat; |
35 | 36 | import androidx.core.app.NotificationCompat; |
36 | 37 | import androidx.core.app.TaskStackBuilder; |
37 | 38 | import android.text.Html; |
@@ -1092,21 +1093,21 @@ private void stopAlarm() { |
1092 | 1093 | } |
1093 | 1094 |
|
1094 | 1095 | private void setAlarmForNextPoint() { |
1095 | | - LOG.debug("Set alarm for " + preferenceHelper.getMinimumLoggingInterval() + " seconds"); |
1096 | | - |
1097 | 1096 | Intent i = new Intent(this, GpsLoggingService.class); |
1098 | 1097 | i.putExtra(IntentConstants.GET_NEXT_POINT, true); |
1099 | 1098 | PendingIntent pi = PendingIntent.getService(this, 0, i, PendingIntent.FLAG_MUTABLE); |
1100 | 1099 | nextPointAlarmManager.cancel(pi); |
1101 | | - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
1102 | | - nextPointAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, |
1103 | | - SystemClock.elapsedRealtime() + preferenceHelper.getMinimumLoggingInterval() * 1000, pi); |
| 1100 | + |
| 1101 | + if(AlarmManagerCompat.canScheduleExactAlarms(nextPointAlarmManager)){ |
| 1102 | + LOG.debug("Setting exact alarm for {}s", preferenceHelper.getMinimumLoggingInterval()); |
| 1103 | + AlarmManagerCompat.setExactAndAllowWhileIdle(nextPointAlarmManager, AlarmManager.ELAPSED_REALTIME_WAKEUP, |
| 1104 | + SystemClock.elapsedRealtime() + preferenceHelper.getMinimumLoggingInterval() * 1000L, pi); |
1104 | 1105 | } |
1105 | 1106 | else { |
1106 | | - nextPointAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, |
1107 | | - SystemClock.elapsedRealtime() + preferenceHelper.getMinimumLoggingInterval() * 1000, pi); |
| 1107 | + LOG.debug("Setting inexact alarm for {}s (exact alarm disallowed/not available)", preferenceHelper.getMinimumLoggingInterval()); |
| 1108 | + AlarmManagerCompat.setAndAllowWhileIdle(nextPointAlarmManager, AlarmManager.ELAPSED_REALTIME_WAKEUP, |
| 1109 | + SystemClock.elapsedRealtime() + preferenceHelper.getMinimumLoggingInterval() * 1000L, pi); |
1108 | 1110 | } |
1109 | | - |
1110 | 1111 | } |
1111 | 1112 |
|
1112 | 1113 |
|
|
0 commit comments