diff --git a/package.json b/package.json
index e81091da7..8bee4a01e 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "phonegap-plugin-push",
"description": "Register and receive push notifications.",
- "version": "1.7.0",
+ "version": "2.0.0",
"homepage": "http://github.com/phonegap/phonegap-plugin-push#readme",
"repository": {
"type": "git",
diff --git a/plugin.xml b/plugin.xml
index 89e6f34dd..a24f66243 100755
--- a/plugin.xml
+++ b/plugin.xml
@@ -4,7 +4,7 @@
xmlns:amazon="http://schemas.android.com/apk/lib/com.amazon.device.ads"
xmlns:rim="http://www.blackberry.com/ns/widgets"
id="phonegap-plugin-push"
- version="1.7.0">
+ version="2.0.0">
PushPlugin
@@ -41,60 +41,39 @@
$SENDER_ID
-
+
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
+ android:name="com.adobe.phonegap.push.GCMIntentService">
-
+
+ android:name="com.adobe.phonegap.push.PushInstanceIDListenerService">
-
+
-
-
-
+
-
diff --git a/src/android/com/adobe/phonegap/push/GCMIntentService.java b/src/android/com/adobe/phonegap/push/GCMIntentService.java
index 79c6c1885..f8212e203 100644
--- a/src/android/com/adobe/phonegap/push/GCMIntentService.java
+++ b/src/android/com/adobe/phonegap/push/GCMIntentService.java
@@ -22,7 +22,8 @@
import android.text.Spanned;
import android.util.Log;
-import com.google.android.gms.gcm.GcmListenerService;
+import com.google.firebase.messaging.FirebaseMessagingService;
+import com.google.firebase.messaging.RemoteMessage;
import org.json.JSONArray;
import org.json.JSONException;
@@ -35,12 +36,13 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import java.util.Random;
@SuppressLint("NewApi")
-public class GCMIntentService extends GcmListenerService implements PushConstants {
+public class GCMIntentService extends FirebaseMessagingService implements PushConstants {
- private static final String LOG_TAG = "PushPlugin_GCMIntentService";
+ private static final String LOG_TAG = "PushPlugin_FCMService";
private static HashMap> messageMap = new HashMap>();
public void setNotification(int notId, String message){
@@ -58,8 +60,19 @@ public void setNotification(int notId, String message){
}
@Override
- public void onMessageReceived(String from, Bundle extras) {
- Log.d(LOG_TAG, "onMessage - from: " + from);
+ public void onMessageReceived(RemoteMessage message){
+
+ Log.d(LOG_TAG, "onMessage - from: " + message.getFrom());
+
+ Bundle extras = new Bundle();
+
+ if (message.getNotification()!=null) {
+ extras.putString(TITLE,message.getNotification().getTitle());
+ extras.putString(MESSAGE,message.getNotification().getBody());
+ }
+ for (Map.Entry entry : message.getData().entrySet()) {
+ extras.putString(entry.getKey(), entry.getValue());
+ }
if (extras != null) {
diff --git a/src/android/com/adobe/phonegap/push/PushInstanceIDListenerService.java b/src/android/com/adobe/phonegap/push/PushInstanceIDListenerService.java
index eaa39a481..4270f22e3 100644
--- a/src/android/com/adobe/phonegap/push/PushInstanceIDListenerService.java
+++ b/src/android/com/adobe/phonegap/push/PushInstanceIDListenerService.java
@@ -5,23 +5,22 @@
import android.content.SharedPreferences;
import android.util.Log;
-import com.google.android.gms.iid.InstanceID;
-import com.google.android.gms.iid.InstanceIDListenerService;
+import com.google.firebase.iid.FirebaseInstanceId;
+import com.google.firebase.iid.FirebaseInstanceIdService;
import org.json.JSONException;
import java.io.IOException;
-public class PushInstanceIDListenerService extends InstanceIDListenerService implements PushConstants {
- public static final String LOG_TAG = "PushPlugin_PushInstanceIDListenerService";
+public class PushInstanceIDListenerService extends FirebaseInstanceIdService implements PushConstants {
+ public static final String LOG_TAG = "PushPlugin_InsIdService";
@Override
public void onTokenRefresh() {
- SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
- String senderID = sharedPref.getString(SENDER_ID, "");
- if (!"".equals(senderID)) {
- Intent intent = new Intent(this, RegistrationIntentService.class);
- startService(intent);
- }
+ // Get updated InstanceID token.
+ String refreshedToken = FirebaseInstanceId.getInstance().getToken();
+ Log.d(LOG_TAG, "Refreshed token: " + refreshedToken);
+ // TODO: Implement this method to send any registration to your app's servers.
+ //sendRegistrationToServer(refreshedToken);
}
}
diff --git a/src/android/com/adobe/phonegap/push/PushPlugin.java b/src/android/com/adobe/phonegap/push/PushPlugin.java
index b5a4e331f..64eecbdd0 100644
--- a/src/android/com/adobe/phonegap/push/PushPlugin.java
+++ b/src/android/com/adobe/phonegap/push/PushPlugin.java
@@ -6,8 +6,8 @@
import android.os.Bundle;
import android.util.Log;
-import com.google.android.gms.gcm.GcmPubSub;
-import com.google.android.gms.iid.InstanceID;
+import com.google.firebase.iid.FirebaseInstanceId;
+import com.google.firebase.messaging.FirebaseMessaging;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
@@ -67,21 +67,7 @@ public void run() {
Log.v(LOG_TAG, "execute: senderID=" + senderID);
- String savedSenderID = sharedPref.getString(SENDER_ID, "");
- String savedRegID = sharedPref.getString(REGISTRATION_ID, "");
-
- // first time run get new token
- if ("".equals(savedRegID)) {
- token = InstanceID.getInstance(getApplicationContext()).getToken(senderID, GCM);
- }
- // new sender ID, re-register
- else if (!savedSenderID.equals(senderID)) {
- token = InstanceID.getInstance(getApplicationContext()).getToken(senderID, GCM);
- }
- // use the saved one
- else {
- token = sharedPref.getString(REGISTRATION_ID, "");
- }
+ token = FirebaseInstanceId.getInstance().getToken();
if (!"".equals(token)) {
JSONObject json = new JSONObject().put(REGISTRATION_ID, token);
@@ -93,15 +79,12 @@ else if (!savedSenderID.equals(senderID)) {
PushPlugin.sendEvent( json );
} else {
- callbackContext.error("Empty registration ID received from GCM");
+ callbackContext.error("Empty registration ID received from FCM");
return;
}
} catch (JSONException e) {
Log.e(LOG_TAG, "execute: Got JSON Exception " + e.getMessage());
callbackContext.error(e.getMessage());
- } catch (IOException e) {
- Log.e(LOG_TAG, "execute: Got JSON Exception " + e.getMessage());
- callbackContext.error(e.getMessage());
}
if (jo != null) {
@@ -142,7 +125,7 @@ public void run() {
if (topics != null && !"".equals(token)) {
unsubscribeFromTopics(topics, token);
} else {
- InstanceID.getInstance(getApplicationContext()).deleteInstanceID();
+ FirebaseInstanceId.getInstance().deleteInstanceId();
Log.v(LOG_TAG, "UNREGISTER");
// Remove shared prefs
@@ -288,14 +271,10 @@ private void subscribeToTopics(JSONArray topics, String registrationToken) {
if (topics != null) {
String topic = null;
for (int i=0; i