diff --git a/src/android/com/adobe/phonegap/push/GCMIntentService.java b/src/android/com/adobe/phonegap/push/GCMIntentService.java index 7be11b68f..1be402033 100644 --- a/src/android/com/adobe/phonegap/push/GCMIntentService.java +++ b/src/android/com/adobe/phonegap/push/GCMIntentService.java @@ -193,22 +193,36 @@ private Bundle normalizeExtras(Bundle extras) { return newExtras; } + private int extractBadgeCount(Bundle extras) { + int count = -1; + String msgcnt = extras.getString(COUNT); + + try { + if (msgcnt != null) { + count = Integer.parseInt(msgcnt); + } + } catch (NumberFormatException e) { + Log.e(LOG_TAG, e.getLocalizedMessage(), e); + } + + return count; + } + private void showNotificationIfPossible (Context context, Bundle extras) { // Send a notification if there is a message or title, otherwise just send data String message = extras.getString(MESSAGE); String title = extras.getString(TITLE); String contentAvailable = extras.getString(CONTENT_AVAILABLE); - String badgeCount = extras.getString(COUNT); + int badgeCount = extractBadgeCount(extras); + if (badgeCount >= 0) { + Log.d(LOG_TAG, "count =[" + badgeCount + "]"); + PushPlugin.setApplicationIconBadgeNumber(context, badgeCount); + } Log.d(LOG_TAG, "message =[" + message + "]"); Log.d(LOG_TAG, "title =[" + title + "]"); Log.d(LOG_TAG, "contentAvailable =[" + contentAvailable + "]"); - Log.d(LOG_TAG, "badgeCount =[" + badgeCount + "]"); - - if (badgeCount != null) { - PushPlugin.setApplicationIconBadgeNumber(context, Integer.parseInt(badgeCount)); - } if ((message != null && message.length() != 0) || (title != null && title.length() != 0)) { @@ -325,7 +339,7 @@ public void createNotification(Context context, Bundle extras) { /* * Notification count */ - setNotificationCount(extras, mBuilder); + setNotificationCount(context, extras, mBuilder); /* * Notification add actions @@ -365,9 +379,9 @@ private void createActions(Bundle extras, NotificationCompat.Builder mBuilder, R pIntent = PendingIntent.getBroadcast(this, i, intent, PendingIntent.FLAG_UPDATE_CURRENT); } NotificationCompat.Action wAction = - new NotificationCompat.Action.Builder(resources.getIdentifier(action.optString(ICON, ""), DRAWABLE, packageName), - action.getString(TITLE), pIntent) - .build(); + new NotificationCompat.Action.Builder(resources.getIdentifier(action.optString(ICON, ""), DRAWABLE, packageName), + action.getString(TITLE), pIntent) + .build(); wActions.add(wAction); mBuilder.addAction(resources.getIdentifier(action.optString(ICON, ""), DRAWABLE, packageName), action.getString(TITLE), pIntent); @@ -382,13 +396,11 @@ private void createActions(Bundle extras, NotificationCompat.Builder mBuilder, R } } - private void setNotificationCount(Bundle extras, NotificationCompat.Builder mBuilder) { - String msgcnt = extras.getString(MSGCNT); - if (msgcnt == null) { - msgcnt = extras.getString(BADGE); - } - if (msgcnt != null) { - mBuilder.setNumber(Integer.parseInt(msgcnt)); + private void setNotificationCount(Context context, Bundle extras, NotificationCompat.Builder mBuilder) { + int count = extractBadgeCount(extras); + if (count >= 0) { + Log.d(LOG_TAG, "count =[" + count + "]"); + mBuilder.setNumber(count); } }