Commit 9f6465dc authored by Robert (Jamie) Munro's avatar Robert (Jamie) Munro
Browse files

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
parent 91e78781
Loading
Loading
Loading
Loading
+0 −1
Changes for README.md: 0 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -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:

			<uses-permission android:name="android.permission.GET_TASKS" />
			<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
			<uses-permission android:name="android.permission.GET_ACCOUNTS" />
			<uses-permission android:name="android.permission.WAKE_LOCK" />
+0 −1
Changes for plugin.xml: 0 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@
		</config-file>

		<config-file target="AndroidManifest.xml" parent="/manifest">
			<uses-permission android:name="android.permission.GET_TASKS" />
			<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
			<uses-permission android:name="android.permission.GET_ACCOUNTS" />
			<uses-permission android:name="android.permission.WAKE_LOCK" />
+4 −18
Changes for src/android/com/plugin/gcm/GCMIntentService.java: 4 added lines, 18 removed lines.
Original line number Diff line number Diff line
@@ -69,16 +69,14 @@ public class GCMIntentService extends GCMBaseIntentService {
		Bundle extras = intent.getExtras();
		if (extras != null)
		{
			boolean	foreground = this.isInForeground();

			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);
			}
		}
	}

	public void createNotification(Context context, Bundle extras)
	{
@@ -143,18 +141,6 @@ public class GCMIntentService extends GCMBaseIntentService {
		return (String)appName;
	}
	
	public boolean isInForeground()
	{
		ActivityManager activityManager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
		List<RunningTaskInfo> 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);