@@ -75,7 +75,7 @@ private void initialize(Activity activity, NotificationCallback notificationCall
75
75
mContext = activity .getApplicationContext ();
76
76
mActivity = activity ;
77
77
if (mBackgroundThread == null )
78
- mBackgroundThread = new UnityNotificationBackgroundThread (mContext , mScheduledNotifications );
78
+ mBackgroundThread = new UnityNotificationBackgroundThread (this , mScheduledNotifications );
79
79
if (mRandom == null )
80
80
mRandom = new Random ();
81
81
mNotificationCallback = notificationCallback ;
@@ -348,7 +348,7 @@ protected void performNotificationScheduling(int id, Notification.Builder notifi
348
348
349
349
if (fireNow ) {
350
350
Notification notification = buildNotificationForSending (mContext , mOpenActivity , notificationBuilder );
351
- notify (mContext , id , notification );
351
+ notify (id , notification );
352
352
}
353
353
}
354
354
@@ -413,10 +413,10 @@ protected static Intent buildOpenAppIntent(Context context, Class className) {
413
413
return openAppIntent ;
414
414
}
415
415
416
- protected static void performNotificationHousekeeping (Context context , Set <String > ids ) {
416
+ void performNotificationHousekeeping (Set <String > ids ) {
417
417
Log .d (TAG_UNITY , "Checking for invalid notification IDs still hanging around" );
418
418
419
- Set <String > invalid = findInvalidNotificationIds (context , ids );
419
+ Set <String > invalid = findInvalidNotificationIds (mContext , ids );
420
420
synchronized (UnityNotificationManager .class ) {
421
421
Set <String > currentIds = new HashSet <>(ids );
422
422
for (String id : invalid ) {
@@ -427,7 +427,7 @@ protected static void performNotificationHousekeeping(Context context, Set<Strin
427
427
428
428
// in case we have saved intents, clear them
429
429
for (String id : invalid )
430
- deleteExpiredNotificationIntent (context , id );
430
+ deleteExpiredNotificationIntent (id );
431
431
}
432
432
433
433
private static Set <String > findInvalidNotificationIds (Context context , Set <String > ids ) {
@@ -503,21 +503,21 @@ protected static String getSharedPrefsNameByNotificationId(String id)
503
503
}
504
504
505
505
// Load all the notification intents from SharedPreferences.
506
- protected static synchronized List <Notification .Builder > loadSavedNotifications (Context context ) {
507
- Set <String > ids = getScheduledNotificationIDs (context );
506
+ synchronized List <Notification .Builder > loadSavedNotifications () {
507
+ Set <String > ids = getScheduledNotificationIDs (mContext );
508
508
509
509
List <Notification .Builder > intent_data_list = new ArrayList ();
510
510
Set <String > idsMarkedForRemoval = new HashSet <String >();
511
511
512
512
for (String id : ids ) {
513
- SharedPreferences prefs = context .getSharedPreferences (getSharedPrefsNameByNotificationId (id ), Context .MODE_PRIVATE );
513
+ SharedPreferences prefs = mContext .getSharedPreferences (getSharedPrefsNameByNotificationId (id ), Context .MODE_PRIVATE );
514
514
Notification .Builder builder = null ;
515
- Object notification = UnityNotificationUtilities .deserializeNotification (context , prefs );
515
+ Object notification = UnityNotificationUtilities .deserializeNotification (mContext , prefs );
516
516
if (notification != null ) {
517
517
if (notification instanceof Notification .Builder )
518
518
builder = (Notification .Builder )notification ;
519
519
else
520
- builder = UnityNotificationUtilities .recoverBuilder (context , (Notification )notification );
520
+ builder = UnityNotificationUtilities .recoverBuilder (mContext , (Notification )notification );
521
521
}
522
522
523
523
if (builder != null )
@@ -530,9 +530,9 @@ protected static synchronized List<Notification.Builder> loadSavedNotifications(
530
530
ids = new HashSet <>(ids );
531
531
for (String id : idsMarkedForRemoval ) {
532
532
ids .remove (id );
533
- deleteExpiredNotificationIntent (context , id );
533
+ deleteExpiredNotificationIntent (id );
534
534
}
535
- saveScheduledNotificationIDs (context , ids );
535
+ saveScheduledNotificationIDs (ids );
536
536
}
537
537
538
538
return intent_data_list ;
@@ -603,8 +603,8 @@ protected static synchronized Set<String> getScheduledNotificationIDs(Context co
603
603
return ids ;
604
604
}
605
605
606
- protected static synchronized void saveScheduledNotificationIDs (Context context , Set <String > ids ) {
607
- SharedPreferences .Editor editor = context .getSharedPreferences (NOTIFICATION_IDS_SHARED_PREFS , Context .MODE_PRIVATE ).edit ().clear ();
606
+ synchronized void saveScheduledNotificationIDs (Set <String > ids ) {
607
+ SharedPreferences .Editor editor = mContext .getSharedPreferences (NOTIFICATION_IDS_SHARED_PREFS , Context .MODE_PRIVATE ).edit ().clear ();
608
608
editor .putStringSet (NOTIFICATION_IDS_SHARED_PREFS_KEY , ids );
609
609
editor .apply ();
610
610
}
@@ -615,22 +615,20 @@ public void cancelPendingNotification(int id) {
615
615
}
616
616
617
617
// Cancel a pending notification by id.
618
- protected static void cancelPendingNotificationIntent (Context context , int id ) {
619
- Intent intent = new Intent (context , UnityNotificationManager .class );
620
- PendingIntent broadcast = getBroadcastPendingIntent (context , id , intent , PendingIntent .FLAG_NO_CREATE );
618
+ void cancelPendingNotificationIntent (int id ) {
619
+ Intent intent = new Intent (mContext , UnityNotificationManager .class );
620
+ PendingIntent broadcast = getBroadcastPendingIntent (mContext , id , intent , PendingIntent .FLAG_NO_CREATE );
621
621
622
622
if (broadcast != null ) {
623
- if (context != null ) {
624
- AlarmManager alarmManager = (AlarmManager ) context .getSystemService (Context .ALARM_SERVICE );
625
- alarmManager .cancel (broadcast );
626
- }
623
+ AlarmManager alarmManager = (AlarmManager ) mContext .getSystemService (Context .ALARM_SERVICE );
624
+ alarmManager .cancel (broadcast );
627
625
broadcast .cancel ();
628
626
}
629
627
}
630
628
631
629
// Delete the notification intent from SharedPreferences by id.
632
- protected static synchronized void deleteExpiredNotificationIntent (Context context , String id ) {
633
- SharedPreferences notificationPrefs = context .getSharedPreferences (getSharedPrefsNameByNotificationId (id ), Context .MODE_PRIVATE );
630
+ synchronized void deleteExpiredNotificationIntent (String id ) {
631
+ SharedPreferences notificationPrefs = mContext .getSharedPreferences (getSharedPrefsNameByNotificationId (id ), Context .MODE_PRIVATE );
634
632
notificationPrefs .edit ().clear ().apply ();
635
633
}
636
634
@@ -688,16 +686,16 @@ public void onReceive(Intent intent) {
688
686
}
689
687
690
688
if (notif != null ) {
691
- UnityNotificationManager . notify (mContext , id , notif );
689
+ notify (id , notif );
692
690
}
693
691
}
694
692
}
695
693
696
694
// Call the system notification service to notify the notification.
697
- protected static void notify (Context context , int id , Notification notification ) {
695
+ private void notify (int id , Notification notification ) {
698
696
boolean showInForeground = notification .extras .getBoolean (KEY_SHOW_IN_FOREGROUND , true );
699
697
if (!isInForeground () || showInForeground ) {
700
- getNotificationManager (context ).notify (id , notification );
698
+ getNotificationManager ().notify (id , notification );
701
699
if (Build .VERSION .SDK_INT < Build .VERSION_CODES .M ) synchronized (UnityNotificationManager .class ) {
702
700
mVisibleNotifications .add (Integer .valueOf (id ));
703
701
}
@@ -706,7 +704,7 @@ protected static void notify(Context context, int id, Notification notification)
706
704
long repeatInterval = notification .extras .getLong (KEY_REPEAT_INTERVAL , -1 );
707
705
if (repeatInterval <= 0 ) {
708
706
mScheduledNotifications .remove (id );
709
- cancelPendingNotificationIntent (context , id );
707
+ cancelPendingNotificationIntent (id );
710
708
}
711
709
712
710
try {
@@ -752,7 +750,7 @@ public Notification.Builder createNotificationBuilder(String channelID) {
752
750
}
753
751
754
752
@ SuppressWarnings ("deprecation" )
755
- protected static Notification .Builder createNotificationBuilder (Context context , String channelID ) {
753
+ static Notification .Builder createNotificationBuilder (Context context , String channelID ) {
756
754
if (Build .VERSION .SDK_INT < Build .VERSION_CODES .O ) {
757
755
Notification .Builder notificationBuilder = new Notification .Builder (context );
758
756
0 commit comments