Commit 76eec9e8 authored by Eddy Verbruggen's avatar Eddy Verbruggen
Browse files

Merge pull request #116 from thenewmr/master

Allow for multiple notifications in Android
parents 54e59bce 728e9754
Loading
Loading
Loading
Loading
+15 −12
Changes for src/android/com/plugin/gcm/GCMIntentService.java: 15 added lines, 12 removed lines.
Original line number Diff line number Diff line
package com.plugin.gcm;

import java.util.List;

import com.google.android.gcm.GCMBaseIntentService;
import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
@@ -18,10 +13,11 @@ import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.google.android.gcm.GCMBaseIntentService;

@SuppressLint("NewApi")
public class GCMIntentService extends GCMBaseIntentService {

	public static final int NOTIFICATION_ID = 237;
	private static final String TAG = "GCMIntentService";
	
	public GCMIntentService() {
@@ -101,7 +97,8 @@ public class GCMIntentService extends GCMBaseIntentService {
				.setWhen(System.currentTimeMillis())
				.setContentTitle(extras.getString("title"))
				.setTicker(extras.getString("title"))
				.setContentIntent(contentIntent);
				.setContentIntent(contentIntent)
				.setAutoCancel(true);

		String message = extras.getString("message");
		if (message != null) {
@@ -115,13 +112,19 @@ public class GCMIntentService extends GCMBaseIntentService {
			mBuilder.setNumber(Integer.parseInt(msgcnt));
		}
		
		mNotificationManager.notify((String) appName, NOTIFICATION_ID, mBuilder.build());
		int notId = 0;
		
		try {
			notId = Integer.parseInt(extras.getString("notId"));
		}
		catch(NumberFormatException e) {
			Log.e(TAG, "Number format exception - Error parsing Notification ID: " + e.getMessage());
		}
		catch(Exception e) {
			Log.e(TAG, "Number format exception - Error parsing Notification ID" + e.getMessage());
		}
		
	public static void cancelNotification(Context context)
	{
		NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
		mNotificationManager.cancel((String)getAppName(context), NOTIFICATION_ID);	
		mNotificationManager.notify((String) appName, notId, mBuilder.build());
	}
	
	private static String getAppName(Context context)
+0 −2
Changes for src/android/com/plugin/gcm/PushHandlerActivity.java: 0 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -25,8 +25,6 @@ public class PushHandlerActivity extends Activity
		boolean isPushPluginActive = PushPlugin.isActive();
		processPushBundle(isPushPluginActive);

		GCMIntentService.cancelNotification(this);

		finish();

		if (!isPushPluginActive) {