35
35
import com .google .android .gms .tasks .Continuation ;
36
36
import com .google .android .gms .tasks .Task ;
37
37
import java .util .List ;
38
+ import java .util .Arrays ;
39
+ import java .util .ArrayList ;
38
40
import java .util .concurrent .ExecutorService ;
39
41
import java .util .concurrent .Executors ;
40
42
@@ -146,9 +148,18 @@ static void scheduleTimestampTriggerNotification(
146
148
147
149
AlarmManager alarmManager = AlarmUtils .getAlarmManager ();
148
150
151
+ TimestampTriggerModel .AlarmType alarmType = timestampTrigger .getAlarmType ();
152
+
149
153
// Verify we can call setExact APIs to avoid a crash, but it requires an Android S+ symbol
150
154
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 ()) {
152
163
System .err .println (
153
164
"Missing SCHEDULE_EXACT_ALARM permission. Trigger not scheduled. See:"
154
165
+ " https://notifee.app/react-native/docs/triggers#android-12-limitations" );
@@ -159,8 +170,6 @@ static void scheduleTimestampTriggerNotification(
159
170
// Ensure timestamp is always in the future when scheduling the alarm
160
171
timestampTrigger .setNextTimestamp ();
161
172
162
- TimestampTriggerModel .AlarmType alarmType = timestampTrigger .getAlarmType ();
163
-
164
173
switch (alarmType ) {
165
174
case SET :
166
175
alarmManager .set (AlarmManager .RTC , timestampTrigger .getTimestamp (), pendingIntent );
0 commit comments