@@ -50,6 +50,7 @@ public class PushPlugin extends CordovaPlugin implements PushConstants {
5050
5151 /**
5252 * Gets the application context from cordova's main activity.
53+ *
5354 * @return the application context
5455 */
5556 private Context getApplicationContext () {
@@ -120,7 +121,8 @@ private void createChannel(JSONObject channel) throws JSONException {
120121 mChannel .setSound (android .provider .Settings .System .DEFAULT_NOTIFICATION_URI , audioAttributes );
121122 }
122123
123- // If vibration settings is an array set vibration pattern, else set enable vibration.
124+ // If vibration settings is an array set vibration pattern, else set enable
125+ // vibration.
124126 JSONArray pattern = channel .optJSONArray (CHANNEL_VIBRATION );
125127 if (pattern != null ) {
126128 int patternLength = pattern .length ();
@@ -146,8 +148,8 @@ private void createDefaultNotificationChannelIfNeeded(JSONObject options) {
146148 final NotificationManager notificationManager = (NotificationManager ) cordova .getActivity ()
147149 .getSystemService (Context .NOTIFICATION_SERVICE );
148150 List <NotificationChannel > channels = notificationManager .getNotificationChannels ();
149-
150- for (int i = 0 ; i < channels .size (); i ++ ) {
151+
152+ for (int i = 0 ; i < channels .size (); i ++) {
151153 id = channels .get (i ).getId ();
152154 if (id .equals (DEFAULT_CHANNEL_ID )) {
153155 return ;
@@ -192,10 +194,18 @@ public void run() {
192194
193195 Log .v (LOG_TAG , "execute: senderID=" + senderID );
194196
195- token = FirebaseInstanceId .getInstance ().getToken ();
197+ try {
198+ token = FirebaseInstanceId .getInstance ().getToken ();
199+ } catch (IllegalStateException e ) {
200+ Log .e (LOG_TAG , "Exception raised while getting Firebase token " + e .getMessage ());
201+ }
196202
197203 if (token == null ) {
198- token = FirebaseInstanceId .getInstance ().getToken (senderID , FCM );
204+ try {
205+ token = FirebaseInstanceId .getInstance ().getToken (senderID , FCM );
206+ } catch (IllegalStateException e ) {
207+ Log .e (LOG_TAG , "Exception raised while getting Firebase token " + e .getMessage ());
208+ }
199209 }
200210
201211 if (!"" .equals (token )) {
@@ -447,8 +457,9 @@ public static void sendError(String message) {
447457 }
448458
449459 /*
450- * Sends the pushbundle extras to the client application.
451- * If the client application isn't currently active and the no-cache flag is not set, it is cached for later processing.
460+ * Sends the pushbundle extras to the client application. If the client
461+ * application isn't currently active and the no-cache flag is not set, it is
462+ * cached for later processing.
452463 */
453464 public static void sendExtras (Bundle extras ) {
454465 if (extras != null ) {
@@ -525,7 +536,8 @@ private void clearAllNotifications() {
525536 private void clearNotification (int id ) {
526537 final NotificationManager notificationManager = (NotificationManager ) cordova .getActivity ()
527538 .getSystemService (Context .NOTIFICATION_SERVICE );
528- String appName = (String ) this .cordova .getActivity ().getPackageManager ().getApplicationLabel (this .cordova .getActivity ().getApplicationInfo ());
539+ String appName = (String ) this .cordova .getActivity ().getPackageManager ()
540+ .getApplicationLabel (this .cordova .getActivity ().getApplicationInfo ());
529541 notificationManager .cancel (appName , id );
530542 }
531543
0 commit comments