Commit 486c8771 authored by Bob Easterday's avatar Bob Easterday
Browse files

Merge pull request #80 from edewit/foreground

added foreground boolean
parents 3cff2aa0 f0b66123
Loading
Loading
Loading
Loading
+2 −2
Changes for src/android/com/plugin/gcm/GCMIntentService.java: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -69,8 +69,8 @@ public class GCMIntentService extends GCMBaseIntentService {
		{
			PushPlugin.sendExtras(extras);

			// Send a notification if there is a message
			if (extras.getString("message").length() != 0) {
			// Send a notification if there is a message and not in foreground
			if (!PushPlugin.isInForeground() && extras.getString("message").length() != 0) {
				createNotification(context, extras);
			}
		}
+19 −0
Changes for src/android/com/plugin/gcm/PushPlugin.java: 19 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ public class PushPlugin extends CordovaPlugin {
	private static String gECB;
	private static String gSenderID;
	private static Bundle gCachedExtras = null;
    private static boolean gForeground = true;

	/**
	 * Gets the application context from cordova's main activity.
@@ -108,6 +109,7 @@ 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 {
@@ -117,6 +119,18 @@ public class PushPlugin extends CordovaPlugin {
		}
	}

    @Override
    public void onPause(boolean multitasking) {
        super.onPause(multitasking);
        gForeground = false;
    }

    @Override
    public void onResume(boolean multitasking) {
        super.onResume(multitasking);
        gForeground = true;
    }

    /*
     * serializes a bundle to JSON.
     */
@@ -201,6 +215,11 @@ public class PushPlugin extends CordovaPlugin {
		return null;      	
    }

    public static boolean isInForeground()
    {
      return gForeground;
    }

    public static boolean isActive()
    {
    	return gWebView != null;