Commit 0eabba59 authored by Bob Easterday's avatar Bob Easterday
Browse files

On Android, don't post notification twice if in the foreground

parent 258e32a7
Loading
Loading
Loading
Loading
+1 −1
Changes for plugin.xml: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
    xmlns:android="http://schemas.android.com/apk/res/android"
    id="com.phonegap.plugins.PushPlugin"
    version="2.0.5">
    version="2.1.0">

    <name>PushPlugin</name>
	<author>Bob Easterday</author>
+7 −0
Changes for src/android/com/plugin/gcm/GCMIntentService.java: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -67,7 +67,13 @@ public class GCMIntentService extends GCMBaseIntentService {
		Bundle extras = intent.getExtras();
		if (extras != null)
		{
			// if we are in the foreground, just surface the payload, else post it to the statusbar
            if (PushPlugin.isInForeground()) {
				extras.putBoolean("foreground", true);
                PushPlugin.sendExtras(extras);
			}
			else {
				extras.putBoolean("foreground", false);

                // Send a notification if there is a message
                if (extras.getString("message").length() != 0) {
@@ -75,6 +81,7 @@ public class GCMIntentService extends GCMBaseIntentService {
                }
            }
        }
	}

	public void createNotification(Context context, Bundle extras)
	{
+2 −4
Changes for src/android/com/plugin/gcm/PushHandlerActivity.java: 2 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -43,12 +43,10 @@ public class PushHandlerActivity extends Activity
		Bundle extras = getIntent().getExtras();

		if (extras != null)	{
			
			Bundle originalExtras = extras.getBundle("pushBundle");
            
			if ( !isPushPluginActive ) { 
				originalExtras.putBoolean("coldstart", true);
			}
            originalExtras.putBoolean("foreground", false);
            originalExtras.putBoolean("coldstart", !isPushPluginActive);

			PushPlugin.sendExtras(originalExtras);
		}
+13 −11
Changes for src/android/com/plugin/gcm/PushPlugin.java: 13 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
@@ -113,7 +114,6 @@ public class PushPlugin extends CordovaPlugin {
	public static void sendExtras(Bundle extras)
	{
		if (extras != null) {
			extras.putBoolean("foreground", gForeground);
			if (gECB != null && gWebView != null) {
				sendJavascript(convertBundleToJson(extras));
			} else {
@@ -124,6 +124,12 @@ public class PushPlugin extends CordovaPlugin {
	}
	
    @Override
    public void initialize(CordovaInterface cordova, CordovaWebView webView) {
        super.initialize(cordova, webView);
        gForeground = true;
    }
	
	@Override
    public void onPause(boolean multitasking) {
        super.onPause(multitasking);
        gForeground = false;
@@ -135,6 +141,12 @@ public class PushPlugin extends CordovaPlugin {
        gForeground = true;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        gForeground = false;
    }

    /*
     * serializes a bundle to JSON.
     */
@@ -228,14 +240,4 @@ public class PushPlugin extends CordovaPlugin {
    {
    	return gWebView != null;
    }
    
	public void onDestroy() 
	{
		GCMRegistrar.onDestroy(getApplicationContext());
		gWebView = null;
		gECB = null;
        gForeground = false;
		
		super.onDestroy();
	}
}