Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/android_alarm_manager_plus/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.3.3

- Fix for periodic alarm being not being exact after some time by adding `allowWhileIdle` parameter

## 1.3.2

- Fix build issue introduced in 1.3.1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,13 @@ public static void setOneShot(Context context, AndroidAlarmManagerPlugin.OneShot
public static void setPeriodic(
Context context, AndroidAlarmManagerPlugin.PeriodicRequest request) {
final boolean repeating = true;
final boolean allowWhileIdle = false;
final boolean alarmClock = false;
scheduleAlarm(
context,
request.requestCode,
alarmClock,
allowWhileIdle,
repeating,
request.allowWhileIdle,
request.exact,
request.wakeup,
request.startMillis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,17 @@ static OneShotRequest fromJson(JSONArray json) throws JSONException {
static final class PeriodicRequest {
static PeriodicRequest fromJson(JSONArray json) throws JSONException {
int requestCode = json.getInt(0);
boolean exact = json.getBoolean(1);
boolean wakeup = json.getBoolean(2);
long startMillis = json.getLong(3);
long intervalMillis = json.getLong(4);
boolean rescheduleOnReboot = json.getBoolean(5);
long callbackHandle = json.getLong(6);
boolean allowWhileIdle = json.getBoolean(1);
boolean exact = json.getBoolean(2);
boolean wakeup = json.getBoolean(3);
long startMillis = json.getLong(4);
long intervalMillis = json.getLong(5);
boolean rescheduleOnReboot = json.getBoolean(6);
long callbackHandle = json.getLong(7);

return new PeriodicRequest(
requestCode,
allowWhileIdle,
exact,
wakeup,
startMillis,
Expand All @@ -222,6 +224,7 @@ static PeriodicRequest fromJson(JSONArray json) throws JSONException {
}

final int requestCode;
final boolean allowWhileIdle;
final boolean exact;
final boolean wakeup;
final long startMillis;
Expand All @@ -231,13 +234,15 @@ static PeriodicRequest fromJson(JSONArray json) throws JSONException {

PeriodicRequest(
int requestCode,
boolean allowWhileIdle,
boolean exact,
boolean wakeup,
long startMillis,
long intervalMillis,
boolean rescheduleOnReboot,
long callbackHandle) {
this.requestCode = requestCode;
this.allowWhileIdle = allowWhileIdle;
this.exact = exact;
this.wakeup = wakeup;
this.startMillis = startMillis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ class AndroidAlarmManager {
/// If `startAt` is passed, the timer will first go off at that time and
/// subsequently run with period `duration`.
///
/// If `allowWhileIdle` is passed as `true`, the timer will be created with
/// Android's `AlarmManagerCompat.setExactAndAllowWhileIdle` or
/// `AlarmManagerCompat.setAndAllowWhileIdle`.
///
/// If `exact` is passed as `true`, the timer will be created with Android's
/// `AlarmManager.setRepeating`. When `exact` is `false` (the default), the
/// timer will be created with `AlarmManager.setInexactRepeating`.
Expand All @@ -265,6 +269,7 @@ class AndroidAlarmManager {
int id,
Function callback, {
DateTime? startAt,
bool allowWhileIdle = false,
bool exact = false,
bool wakeup = false,
bool rescheduleOnReboot = false,
Expand All @@ -282,6 +287,7 @@ class AndroidAlarmManager {
}
final r = await _channel.invokeMethod<bool>('Alarm.periodic', <dynamic>[
id,
allowWhileIdle,
exact,
wakeup,
first,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ void main() {
CallbackHandle.fromRawHandle(rawHandle));

final id = 1;
final allowWhileIdle = true;
final exact = true;
final wakeup = true;
final rescheduleOnReboot = true;
Expand All @@ -163,20 +164,22 @@ void main() {
testChannel.setMockMethodCallHandler((MethodCall call) async {
expect(call.method, 'Alarm.periodic');
expect(call.arguments[0], id);
expect(call.arguments[1], exact);
expect(call.arguments[2], wakeup);
expect(call.arguments[3],
expect(call.arguments[1], allowWhileIdle);
expect(call.arguments[2], exact);
expect(call.arguments[3], wakeup);
expect(call.arguments[4],
(now.millisecondsSinceEpoch + period.inMilliseconds));
expect(call.arguments[4], period.inMilliseconds);
expect(call.arguments[5], rescheduleOnReboot);
expect(call.arguments[6], rawHandle);
expect(call.arguments[5], period.inMilliseconds);
expect(call.arguments[6], rescheduleOnReboot);
expect(call.arguments[7], rawHandle);
return true;
});

final result = await AndroidAlarmManager.periodic(
period,
id,
(int id) => null,
allowWhileIdle: allowWhileIdle,
exact: exact,
wakeup: wakeup,
rescheduleOnReboot: rescheduleOnReboot,
Expand Down