Skip to content

Commit f7c59f6

Browse files
authoredJun 10, 2024
fix(android): fix an issue when using inexact alarms (#981)
1 parent 0239339 commit f7c59f6

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed
 

‎android/src/main/java/app/notifee/core/NotifeeAlarmManager.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import com.google.android.gms.tasks.Continuation;
3636
import com.google.android.gms.tasks.Task;
3737
import java.util.List;
38+
import java.util.Arrays;
39+
import java.util.ArrayList;
3840
import java.util.concurrent.ExecutorService;
3941
import java.util.concurrent.Executors;
4042

@@ -146,9 +148,18 @@ static void scheduleTimestampTriggerNotification(
146148

147149
AlarmManager alarmManager = AlarmUtils.getAlarmManager();
148150

151+
TimestampTriggerModel.AlarmType alarmType = timestampTrigger.getAlarmType();
152+
149153
// Verify we can call setExact APIs to avoid a crash, but it requires an Android S+ symbol
150154
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
151-
if (!alarmManager.canScheduleExactAlarms()) {
155+
156+
// Check whether the alarmType is the exact alarm
157+
boolean isExactAlarm = Arrays
158+
.asList(TimestampTriggerModel.AlarmType.SET_EXACT,
159+
TimestampTriggerModel.AlarmType.SET_EXACT_AND_ALLOW_WHILE_IDLE,
160+
TimestampTriggerModel.AlarmType.SET_ALARM_CLOCK)
161+
.contains(alarmType);
162+
if (isExactAlarm && !alarmManager.canScheduleExactAlarms()) {
152163
System.err.println(
153164
"Missing SCHEDULE_EXACT_ALARM permission. Trigger not scheduled. See:"
154165
+ " https://notifee.app/react-native/docs/triggers#android-12-limitations");
@@ -159,8 +170,6 @@ static void scheduleTimestampTriggerNotification(
159170
// Ensure timestamp is always in the future when scheduling the alarm
160171
timestampTrigger.setNextTimestamp();
161172

162-
TimestampTriggerModel.AlarmType alarmType = timestampTrigger.getAlarmType();
163-
164173
switch (alarmType) {
165174
case SET:
166175
alarmManager.set(AlarmManager.RTC, timestampTrigger.getTimestamp(), pendingIntent);

0 commit comments

Comments
 (0)