29
29
30
30
import android .app .AlarmManager ;
31
31
import android .app .PendingIntent ;
32
- import android .app .NotificationManager ;
33
32
import android .app .job .JobInfo ;
34
33
import android .app .job .JobScheduler ;
35
34
import android .content .ComponentName ;
@@ -230,8 +229,7 @@ private static Intent addRestoreExtras(Intent intent, Cursor cursor) {
230
229
231
230
private static final int RESTORE_NOTIFICATIONS_DELAY_MS = 15_000 ;
232
231
static void startDelayedRestoreTaskFromReceiver (Context context ) {
233
- if (android .os .Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
234
- // NotificationRestorer#restore is Code-sensitive to Android O
232
+ if (android .os .Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
235
233
OneSignal .Log (OneSignal .LOG_LEVEL .INFO , "scheduleRestoreKickoffJob" );
236
234
237
235
// set the job id to android notif id - that way we don't restore any notif twice
@@ -251,12 +249,15 @@ static void startDelayedRestoreTaskFromReceiver(Context context) {
251
249
intentForService .setComponent (new ComponentName (context .getPackageName (),
252
250
NotificationRestoreService .class .getName ()));
253
251
252
+ // KEEP - PendingIntent.FLAG_UPDATE_CURRENT
253
+ // Some Samsung devices will throw the below exception otherwise.
254
+ // "java.lang.SecurityException: !@Too many alarms (500) registered"
254
255
PendingIntent pendingIntent = PendingIntent .getService (context ,
255
- RESTORE_KICKOFF_REQUEST_CODE , intentForService , PendingIntent .FLAG_CANCEL_CURRENT );
256
+ RESTORE_KICKOFF_REQUEST_CODE , intentForService , PendingIntent .FLAG_UPDATE_CURRENT );
256
257
257
258
long scheduleTime = System .currentTimeMillis () + RESTORE_NOTIFICATIONS_DELAY_MS ;
258
259
AlarmManager alarm = (AlarmManager )context .getSystemService (Context .ALARM_SERVICE );
259
260
alarm .set (AlarmManager .RTC , scheduleTime , pendingIntent );
260
261
}
261
262
}
262
- }
263
+ }
0 commit comments