Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #102 from slorber/master
Browse files Browse the repository at this point in the history
Use fallback method for extras.getString: add "gcm.notification." prefix
  • Loading branch information
macdonst committed Sep 7, 2015
2 parents 31e199a + b406b37 commit 35155b1
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/android/com/adobe/phonegap/push/GCMIntentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public void createNotification(Context context, Bundle extras) {
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setWhen(System.currentTimeMillis())
.setContentTitle(extras.getString("title"))
.setTicker(extras.getString("title"))
.setContentTitle(getString(extras,"title"))
.setTicker(getString(extras,"title"))
.setContentIntent(contentIntent)
.setAutoCancel(true);

Expand Down Expand Up @@ -147,7 +147,7 @@ public void createNotification(Context context, Bundle extras) {
* To use, add the `iconColor` key to plugin android options
*
*/
setNotificationIconColor(extras.getString("color"), mBuilder, localIconColor);
setNotificationIconColor(getString(extras,"color"), mBuilder, localIconColor);

/*
* Notification Icon
Expand Down Expand Up @@ -299,19 +299,27 @@ private void setNotificationMessage(Bundle extras, NotificationCompat.Builder mB
}
}
}

private String getString(Bundle extras,String key) {
String message = extras.getString(key);
if (message == null) {
message = extras.getString("gcm.notification."+key);
}
return message;
}

private String getMessageText(Bundle extras) {
String message = extras.getString("message");
String message = getString(extras,"message");
if (message == null) {
message = extras.getString("body");
message = getString(extras,"body");
}
return message;
}

private void setNotificationSound(Context context, Bundle extras, NotificationCompat.Builder mBuilder) {
String soundname = extras.getString("soundname");
String soundname = getString(extras,"soundname");
if (soundname == null) {
soundname = extras.getString("sound");
soundname = getString(extras,"sound");
}
if (soundname != null) {
Uri sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE
Expand All @@ -324,7 +332,7 @@ private void setNotificationSound(Context context, Bundle extras, NotificationCo
}

private void setNotificationLargeIcon(Bundle extras, String packageName, Resources resources, NotificationCompat.Builder mBuilder) {
String gcmLargeIcon = extras.getString("image"); // from gcm
String gcmLargeIcon = getString(extras,"image"); // from gcm
if (gcmLargeIcon != null) {
if (gcmLargeIcon.startsWith("http://") || gcmLargeIcon.startsWith("https://")) {
mBuilder.setLargeIcon(getBitmapFromURL(gcmLargeIcon));
Expand Down Expand Up @@ -354,7 +362,7 @@ private void setNotificationLargeIcon(Bundle extras, String packageName, Resourc

private void setNotificationSmallIcon(Context context, Bundle extras, String packageName, Resources resources, NotificationCompat.Builder mBuilder, String localIcon) {
int iconId = 0;
String icon = extras.getString("icon");
String icon = getString(extras,"icon");
if (icon != null) {
iconId = resources.getIdentifier(icon, "drawable", packageName);
Log.d(LOG_TAG, "using icon from plugin options");
Expand Down Expand Up @@ -435,4 +443,4 @@ private int parseInt(String value, Bundle extras) {

return retval;
}
}
}

0 comments on commit 35155b1

Please sign in to comment.