@@ -80,13 +80,19 @@ private AlarmManager getAlarmManager() {
8080 }
8181
8282 private PendingIntent toScheduleNotificationIntent (Bundle bundle ) {
83- int notificationID = Integer .parseInt (bundle .getString ("id" ));
83+ try {
84+ int notificationID = Integer .parseInt (bundle .getString ("id" ));
85+
86+ Intent notificationIntent = new Intent (context , RNPushNotificationPublisher .class );
87+ notificationIntent .putExtra (RNPushNotificationPublisher .NOTIFICATION_ID , notificationID );
88+ notificationIntent .putExtras (bundle );
8489
85- Intent notificationIntent = new Intent (context , RNPushNotificationPublisher .class );
86- notificationIntent .putExtra (RNPushNotificationPublisher .NOTIFICATION_ID , notificationID );
87- notificationIntent .putExtras (bundle );
90+ return PendingIntent .getBroadcast (context , notificationID , notificationIntent , PendingIntent .FLAG_UPDATE_CURRENT );
91+ } catch (Exception e ) {
92+ Log .e (LOG_TAG , "Unable to parse Notification ID" , e );
93+ }
8894
89- return PendingIntent . getBroadcast ( context , notificationID , notificationIntent , PendingIntent . FLAG_UPDATE_CURRENT ) ;
95+ return null ;
9096 }
9197
9298 public void sendNotificationScheduled (Bundle bundle ) {
@@ -137,6 +143,10 @@ public void sendNotificationScheduledCore(Bundle bundle) {
137143 // notification to the user
138144 PendingIntent pendingIntent = toScheduleNotificationIntent (bundle );
139145
146+ if (pendingIntent == null ) {
147+ return ;
148+ }
149+
140150 Log .d (LOG_TAG , String .format ("Setting a notification with id %s at time %s" ,
141151 bundle .getString ("id" ), Long .toString (fireDate )));
142152 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .KITKAT ) {
@@ -636,7 +646,11 @@ private void cancelScheduledNotification(String notificationIDString) {
636646 // remove it from the alarm manger schedule
637647 Bundle b = new Bundle ();
638648 b .putString ("id" , notificationIDString );
639- getAlarmManager ().cancel (toScheduleNotificationIntent (b ));
649+ PendingIntent pendingIntent = toScheduleNotificationIntent (b );
650+
651+ if (pendingIntent != null ) {
652+ getAlarmManager ().cancel (pendingIntent );
653+ }
640654
641655 if (scheduledNotificationsPersistence .contains (notificationIDString )) {
642656 // remove it from local storage
@@ -650,7 +664,11 @@ private void cancelScheduledNotification(String notificationIDString) {
650664 // removed it from the notification center
651665 NotificationManager notificationManager = notificationManager ();
652666
653- notificationManager .cancel (Integer .parseInt (notificationIDString ));
667+ try {
668+ notificationManager .cancel (Integer .parseInt (notificationIDString ));
669+ } catch (Exception e ) {
670+ Log .e (LOG_TAG , "Unable to parse Notification ID " + notificationIDString , e );
671+ }
654672 }
655673
656674 private NotificationManager notificationManager () {
0 commit comments