Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 51ccb72

Browse files
committed
using api that will allow alarms in doze mode
1 parent 51ac2d2 commit 51ccb72

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

packages/android_alarm_manager/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ android {
2525
compileSdkVersion 27
2626

2727
defaultConfig {
28-
minSdkVersion 16
28+
minSdkVersion 19
2929
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
3030
}
3131
lintOptions {

packages/android_alarm_manager/android/src/main/java/io/flutter/plugins/androidalarmmanager/AlarmService.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.app.Service;
1010
import android.content.Context;
1111
import android.content.Intent;
12+
import android.os.Build;
1213
import android.os.IBinder;
1314
import android.util.Log;
1415
import io.flutter.plugin.common.MethodChannel;
@@ -192,13 +193,21 @@ private static void scheduleAlarm(
192193
if (repeating) {
193194
manager.setRepeating(clock, startMillis, intervalMillis, pendingIntent);
194195
} else {
195-
manager.setExact(clock, startMillis, pendingIntent);
196+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
197+
manager.setExactAndAllowWhileIdle(clock, startMillis, pendingIntent);
198+
} else {
199+
manager.setExact(clock, startMillis, pendingIntent);
200+
}
196201
}
197202
} else {
198203
if (repeating) {
199204
manager.setInexactRepeating(clock, startMillis, intervalMillis, pendingIntent);
200205
} else {
201-
manager.set(clock, startMillis, pendingIntent);
206+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
207+
manager.setAndAllowWhileIdle(clock, startMillis, pendingIntent);
208+
} else {
209+
manager.set(clock, startMillis, pendingIntent);
210+
}
202211
}
203212
}
204213
}

0 commit comments

Comments
 (0)