Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
🐛🐧 Issue phonegap#2489: Crash reports on Google Play Store - firebase…
Browse files Browse the repository at this point in the history
… IllegalStateException
  • Loading branch information
macdonst committed Aug 15, 2018
1 parent 110e3c2 commit 4cf09ab
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/android/com/adobe/phonegap/push/PushPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class PushPlugin extends CordovaPlugin implements PushConstants {

/**
* Gets the application context from cordova's main activity.
*
* @return the application context
*/
private Context getApplicationContext() {
Expand Down Expand Up @@ -120,7 +121,8 @@ private void createChannel(JSONObject channel) throws JSONException {
mChannel.setSound(android.provider.Settings.System.DEFAULT_NOTIFICATION_URI, audioAttributes);
}

// If vibration settings is an array set vibration pattern, else set enable vibration.
// If vibration settings is an array set vibration pattern, else set enable
// vibration.
JSONArray pattern = channel.optJSONArray(CHANNEL_VIBRATION);
if (pattern != null) {
int patternLength = pattern.length();
Expand All @@ -146,8 +148,8 @@ private void createDefaultNotificationChannelIfNeeded(JSONObject options) {
final NotificationManager notificationManager = (NotificationManager) cordova.getActivity()
.getSystemService(Context.NOTIFICATION_SERVICE);
List<NotificationChannel> channels = notificationManager.getNotificationChannels();
for (int i=0; i<channels.size(); i++ ) {

for (int i = 0; i < channels.size(); i++) {
id = channels.get(i).getId();
if (id.equals(DEFAULT_CHANNEL_ID)) {
return;
Expand Down Expand Up @@ -192,10 +194,18 @@ public void run() {

Log.v(LOG_TAG, "execute: senderID=" + senderID);

token = FirebaseInstanceId.getInstance().getToken();
try {
token = FirebaseInstanceId.getInstance().getToken();
} catch (IllegalStateException e) {
Log.e(LOG_TAG, "Exception raised while getting Firebase token " + e.getMessage());
}

if (token == null) {
token = FirebaseInstanceId.getInstance().getToken(senderID, FCM);
try {
token = FirebaseInstanceId.getInstance().getToken(senderID, FCM);
} catch (IllegalStateException e) {
Log.e(LOG_TAG, "Exception raised while getting Firebase token " + e.getMessage());
}
}

if (!"".equals(token)) {
Expand Down Expand Up @@ -447,8 +457,9 @@ public static void sendError(String message) {
}

/*
* Sends the pushbundle extras to the client application.
* If the client application isn't currently active and the no-cache flag is not set, it is cached for later processing.
* Sends the pushbundle extras to the client application. If the client
* application isn't currently active and the no-cache flag is not set, it is
* cached for later processing.
*/
public static void sendExtras(Bundle extras) {
if (extras != null) {
Expand Down Expand Up @@ -525,7 +536,8 @@ private void clearAllNotifications() {
private void clearNotification(int id) {
final NotificationManager notificationManager = (NotificationManager) cordova.getActivity()
.getSystemService(Context.NOTIFICATION_SERVICE);
String appName = (String) this.cordova.getActivity().getPackageManager().getApplicationLabel(this.cordova.getActivity().getApplicationInfo());
String appName = (String) this.cordova.getActivity().getPackageManager()
.getApplicationLabel(this.cordova.getActivity().getApplicationInfo());
notificationManager.cancel(appName, id);
}

Expand Down

0 comments on commit 4cf09ab

Please sign in to comment.