From 9f6465dcd5ab6ddf543c145de8bd4493a8b33589 Mon Sep 17 00:00:00 2001 From: "Robert (Jamie) Munro" Date: Tue, 10 Sep 2013 15:20:09 +0100 Subject: [PATCH] Eliminate need for GET_TASKS permission * Don't check if we are in the foreground - that happens anyway in the sendExtras() method (https://github.com/phonegap-build/PushPlugin/blob/master/src/android/com/plugin/gcm/PushPlugin.java#L111) * Only display a message if the message has text to be displayed Fixes #52 and undoes #3 --- README.md | 1 - plugin.xml | 1 - .../com/plugin/gcm/GCMIntentService.java | 22 ++++--------------- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index beda22cc..533950b8 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,6 @@ This plugin is for use with [Cordova](http://incubator.apache.org/cordova/), and 2) Modify your **AndroidManifest.xml** and add the following lines to your manifest tag: - diff --git a/plugin.xml b/plugin.xml index 6bd9d925..4d3678d8 100755 --- a/plugin.xml +++ b/plugin.xml @@ -29,7 +29,6 @@ - diff --git a/src/android/com/plugin/gcm/GCMIntentService.java b/src/android/com/plugin/gcm/GCMIntentService.java index 9a46aa4a..9ea6748b 100644 --- a/src/android/com/plugin/gcm/GCMIntentService.java +++ b/src/android/com/plugin/gcm/GCMIntentService.java @@ -69,14 +69,12 @@ protected void onMessage(Context context, Intent intent) { Bundle extras = intent.getExtras(); if (extras != null) { - boolean foreground = this.isInForeground(); + PushPlugin.sendExtras(extras); - extras.putBoolean("foreground", foreground); - - if (foreground) - PushPlugin.sendExtras(extras); - else + // Send a notification if there is a message + if (extras.getString("message").length() != 0) { createNotification(context, extras); + } } } @@ -143,18 +141,6 @@ private static String getAppName(Context context) return (String)appName; } - public boolean isInForeground() - { - ActivityManager activityManager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE); - List services = activityManager - .getRunningTasks(Integer.MAX_VALUE); - - if (services.get(0).topActivity.getPackageName().toString().equalsIgnoreCase(getApplicationContext().getPackageName().toString())) - return true; - - return false; - } - @Override public void onError(Context context, String errorId) { Log.e(TAG, "onError - errorId: " + errorId);