Skip to content

Various (manually) merged changes #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 2, 2014
Merged
3 changes: 3 additions & 0 deletions Example/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@
function onNotificationAPN(e) {
if (e.alert) {
$("#app-status-ul").append('<li>push-notification: ' + e.alert + '</li>');
// showing an alert also requires the org.apache.cordova.dialogs plugin
navigator.notification.alert(e.alert);
}

if (e.sound) {
// playing a sound also requires the org.apache.cordova.media plugin
var snd = new Media(e.sound);
snd.play();
}
Expand Down Expand Up @@ -106,6 +108,7 @@
// On Amazon FireOS all custom attributes are contained within payload
var soundfile = e.soundname || e.payload.sound;
// if the notification contains a soundname, play it.
// playing a sound also requires the org.apache.cordova.media plugin
var my_media = new Media("/android_asset/www/"+ soundfile);

my_media.play();
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,23 @@ The final hierarchy will likely look something like this:
<service android:name="com.plugin.gcm.GCMIntentService" />
```

4) Modify your `res/xml/config.xml` to include the following line in order to tell Cordova to include this plugin and where it can be found: (See the Sample_config.xml file in the Example folder)
4) Check that the launch mode for the main Cordova Activity is one of the **[singleXXX](http://developer.android.com/guide/topics/manifest/activity-element.html#lmode)** options in **AndroidManifest.xml**.

```xml
<activity ... android:launchMode="singleTop">
```

Otherwise a new activity instance, with a new webview, will be created when activating the notifications.

5) Modify your `res/xml/config.xml` to include the following line in order to tell Cordova to include this plugin and where it can be found: (See the Sample_config.xml file in the Example folder)

```xml
<feature name="PushPlugin">
<param name="android-package" value="com.plugin.gcm.PushPlugin" />
</feature>
```

5) Add the `PushNotification.js` script to your assets/www folder (or javascripts folder, wherever you want really) and reference it in your main index.html file. This file's usage is described in the **Plugin API** section below.
6) Add the `PushNotification.js` script to your assets/www folder (or javascripts folder, wherever you want really) and reference it in your main index.html file. This file's usage is described in the **Plugin API** section below.

```html
<script type="text/javascript" charset="utf-8" src="PushNotification.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:amazon="http://schemas.android.com/apk/lib/com.amazon.device.ads"
id="com.phonegap.plugins.PushPlugin"
version="2.2.0">
version="2.2.1">

<name>PushPlugin</name>
<author>Bob Easterday</author>
Expand Down Expand Up @@ -45,7 +45,7 @@
</config-file>

<config-file target="AndroidManifest.xml" parent="/manifest/application">
<activity android:name="com.plugin.gcm.PushHandlerActivity"/>
<activity android:name="com.plugin.gcm.PushHandlerActivity" android:exported="true"/>
<receiver android:name="com.plugin.gcm.CordovaGCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
Expand Down
Binary file modified src/android/com/plugin/android-support-v13.jar
Binary file not shown.
41 changes: 26 additions & 15 deletions src/android/com/plugin/gcm/GCMIntentService.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
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;
Expand All @@ -18,10 +13,11 @@
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() {
Expand Down Expand Up @@ -94,14 +90,23 @@ public void createNotification(Context context, Bundle extras)

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

int defaults = Notification.DEFAULT_ALL;

if (extras.getString("defaults") != null) {
try {
defaults = Integer.parseInt(extras.getString("defaults"));
} catch (NumberFormatException e) {}
}

NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setDefaults(Notification.DEFAULT_ALL)
.setDefaults(defaults)
.setSmallIcon(context.getApplicationInfo().icon)
.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) {
Expand All @@ -115,13 +120,19 @@ public void createNotification(Context context, Bundle extras)
mBuilder.setNumber(Integer.parseInt(msgcnt));
}

mNotificationManager.notify((String) appName, NOTIFICATION_ID, mBuilder.build());
}

public static void cancelNotification(Context context)
{
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel((String)getAppName(context), NOTIFICATION_ID);
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());
}

mNotificationManager.notify((String) appName, notId, mBuilder.build());
}

private static String getAppName(Context context)
Expand Down
2 changes: 0 additions & 2 deletions src/android/com/plugin/gcm/PushHandlerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public void onCreate(Bundle savedInstanceState)
boolean isPushPluginActive = PushPlugin.isActive();
processPushBundle(isPushPluginActive);

GCMIntentService.cancelNotification(this);

finish();

if (!isPushPluginActive) {
Expand Down
8 changes: 5 additions & 3 deletions src/ios/PushPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,11 @@ - (void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
}
-(void)successWithMessage:(NSString *)message
{
CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message];

[self.commandDelegate sendPluginResult:commandResult callbackId:self.callbackId];
if (self.callbackId != nil)
{
CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message];
[self.commandDelegate sendPluginResult:commandResult callbackId:self.callbackId];
}
}

-(void)failWithMessage:(NSString *)message withError:(NSError *)error
Expand Down
2 changes: 1 addition & 1 deletion www/PushNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ if (!window.plugins.pushNotification) {
window.plugins.pushNotification = new PushNotification();
}

if (module.exports) {
if (typeof module != 'undefined' && module.exports) {
module.exports = PushNotification;
}