diff --git a/src/android/com/adobe/phonegap/push/GCMIntentService.java b/src/android/com/adobe/phonegap/push/GCMIntentService.java index 943b2cd3a..407923269 100644 --- a/src/android/com/adobe/phonegap/push/GCMIntentService.java +++ b/src/android/com/adobe/phonegap/push/GCMIntentService.java @@ -33,6 +33,7 @@ import com.google.android.gcm.GCMBaseIntentService; import java.util.ArrayList; +import java.util.HashMap; @SuppressLint("NewApi") public class GCMIntentService extends GCMBaseIntentService { @@ -41,11 +42,17 @@ public class GCMIntentService extends GCMBaseIntentService { private static final String STYLE_INBOX = "inbox"; private static final String STYLE_PICTURE = "picture"; private static final String STYLE_TEXT = "text"; - private static ArrayList messageList = new ArrayList(); + private static HashMap> messageMap = new HashMap>(); - public void setNotification(String message){ - if(message == ""){ + public void setNotification(int notId, String message){ + ArrayList messageList = messageMap.get(notId); + if(messageList == null) { + messageList = new ArrayList(); + messageMap.put(notId, messageList); + } + + if(message.isEmpty()){ messageList.clear(); }else{ messageList.add(message); @@ -109,20 +116,22 @@ public void createNotification(Context context, Bundle extras) { String packageName = context.getPackageName(); Resources resources = context.getResources(); + int notId = parseInt("notId", extras); Intent notificationIntent = new Intent(this, PushHandlerActivity.class); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationIntent.putExtra("pushBundle", extras); + notificationIntent.putExtra("notId", notId); int requestCode = new Random().nextInt(); PendingIntent contentIntent = PendingIntent.getActivity(this, requestCode, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = - new NotificationCompat.Builder(context) - .setWhen(System.currentTimeMillis()) - .setContentTitle(getString(extras, "title")) - .setTicker(getString(extras, "title")) - .setContentIntent(contentIntent) - .setAutoCancel(true); + new NotificationCompat.Builder(context) + .setWhen(System.currentTimeMillis()) + .setContentTitle(getString(extras, "title")) + .setTicker(getString(extras, "title")) + .setContentIntent(contentIntent) + .setAutoCancel(true); SharedPreferences prefs = context.getSharedPreferences(PushPlugin.COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE); String localIcon = prefs.getString("icon", null); @@ -197,7 +206,7 @@ public void createNotification(Context context, Bundle extras) { /* * Notification message */ - setNotificationMessage(extras, mBuilder); + setNotificationMessage(notId, extras, mBuilder); /* * Notification count @@ -209,8 +218,6 @@ public void createNotification(Context context, Bundle extras) { */ createActions(extras, mBuilder, resources, packageName); - int notId = parseInt("notId", extras); - mNotificationManager.notify((String) appName, notId, mBuilder.build()); } @@ -266,15 +273,16 @@ private void setNotificationVibration(Bundle extras, Boolean vibrateOption, Noti } } - private void setNotificationMessage(Bundle extras, NotificationCompat.Builder mBuilder) { + private void setNotificationMessage(int notId, Bundle extras, NotificationCompat.Builder mBuilder) { String message = getMessageText(extras); String style = getString(extras, "style", STYLE_TEXT); if(STYLE_INBOX.equals(style)) { - setNotification(message); + setNotification(notId, message); mBuilder.setContentText(message); + ArrayList messageList = messageMap.get(notId); Integer sizeList = messageList.size(); if (sizeList > 1) { String sizeListMessage = sizeList.toString(); @@ -294,7 +302,7 @@ private void setNotificationMessage(Bundle extras, NotificationCompat.Builder mB mBuilder.setStyle(notificationInbox); } } else if (STYLE_PICTURE.equals(style)) { - setNotification(""); + setNotification(notId, ""); NotificationCompat.BigPictureStyle bigPicture = new NotificationCompat.BigPictureStyle(); bigPicture.bigPicture(getBitmapFromURL(getString(extras, "picture"))); @@ -306,7 +314,7 @@ private void setNotificationMessage(Bundle extras, NotificationCompat.Builder mB mBuilder.setStyle(bigPicture); } else { - setNotification(""); + setNotification(notId, ""); NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle(); @@ -327,7 +335,7 @@ private void setNotificationMessage(Bundle extras, NotificationCompat.Builder mB } } } - + private String getString(Bundle extras,String key) { String message = extras.getString(key); if (message == null) { @@ -337,7 +345,7 @@ private String getString(Bundle extras,String key) { } private String getString(Bundle extras,String key, String defaultString) { - String message = extras.getString(key, defaultString); + String message = extras.getString(key); if (message == null) { message = extras.getString("gcm.notification."+key, defaultString); } @@ -359,7 +367,7 @@ private void setNotificationSound(Context context, Bundle extras, NotificationCo } if (soundname != null) { Uri sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE - + "://" + context.getPackageName() + "/raw/" + soundname); + + "://" + context.getPackageName() + "/raw/" + soundname); Log.d(LOG_TAG, sound.toString()); mBuilder.setSound(sound); } else { diff --git a/src/android/com/adobe/phonegap/push/PushHandlerActivity.java b/src/android/com/adobe/phonegap/push/PushHandlerActivity.java index 638dfc5e0..b8a799630 100644 --- a/src/android/com/adobe/phonegap/push/PushHandlerActivity.java +++ b/src/android/com/adobe/phonegap/push/PushHandlerActivity.java @@ -10,20 +10,20 @@ public class PushHandlerActivity extends Activity { - private static String LOG_TAG = "PushPlugin_PushHandlerActivity"; + private static String LOG_TAG = "PushPlugin_PushHandlerActivity"; - /* - * this activity will be started if the user touches a notification that we own. - * We send it's data off to the push plugin for processing. - * If needed, we boot up the main activity to kickstart the application. - * @see android.app.Activity#onCreate(android.os.Bundle) - */ - @Override - public void onCreate(Bundle savedInstanceState) { - GCMIntentService gcm = new GCMIntentService(); - gcm.setNotification(""); - super.onCreate(savedInstanceState); - Log.v(LOG_TAG, "onCreate"); + /* + * this activity will be started if the user touches a notification that we own. + * We send it's data off to the push plugin for processing. + * If needed, we boot up the main activity to kickstart the application. + * @see android.app.Activity#onCreate(android.os.Bundle) + */ + @Override + public void onCreate(Bundle savedInstanceState) { + GCMIntentService gcm = new GCMIntentService(); + gcm.setNotification(getIntent().getIntExtra("notId", 0), ""); + super.onCreate(savedInstanceState); + Log.v(LOG_TAG, "onCreate"); boolean isPushPluginActive = PushPlugin.isActive(); processPushBundle(isPushPluginActive); @@ -33,34 +33,34 @@ public void onCreate(Bundle savedInstanceState) { if (!isPushPluginActive) { forceMainActivityReload(); } - } + } - /** - * Takes the pushBundle extras from the intent, - * and sends it through to the PushPlugin for processing. - */ - private void processPushBundle(boolean isPushPluginActive) { - Bundle extras = getIntent().getExtras(); + /** + * Takes the pushBundle extras from the intent, + * and sends it through to the PushPlugin for processing. + */ + private void processPushBundle(boolean isPushPluginActive) { + Bundle extras = getIntent().getExtras(); - if (extras != null) { - Bundle originalExtras = extras.getBundle("pushBundle"); + if (extras != null) { + Bundle originalExtras = extras.getBundle("pushBundle"); originalExtras.putBoolean("foreground", false); originalExtras.putBoolean("coldstart", !isPushPluginActive); originalExtras.putString("callback", getIntent().getExtras().getString("callback")); - PushPlugin.sendExtras(originalExtras); - } - } + PushPlugin.sendExtras(originalExtras); + } + } - /** - * Forces the main activity to re-launch if it's unloaded. - */ - private void forceMainActivityReload() { - PackageManager pm = getPackageManager(); - Intent launchIntent = pm.getLaunchIntentForPackage(getApplicationContext().getPackageName()); - startActivity(launchIntent); - } + /** + * Forces the main activity to re-launch if it's unloaded. + */ + private void forceMainActivityReload() { + PackageManager pm = getPackageManager(); + Intent launchIntent = pm.getLaunchIntentForPackage(getApplicationContext().getPackageName()); + startActivity(launchIntent); + } @Override protected void onResume() {