Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
Added topic subscription/unsubscription
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile committed Jun 10, 2016
1 parent 2fac903 commit 22c7859
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
7 changes: 7 additions & 0 deletions src/android/com/adobe/phonegap/push/GCMIntentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,15 @@ public void setNotification(int notId, String message){

@Override
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<String, String> entry : message.getData().entrySet()) {
extras.putString(entry.getKey(), entry.getValue());
}
Expand Down
30 changes: 12 additions & 18 deletions src/android/com/adobe/phonegap/push/PushPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.util.Log;

import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.messaging.FirebaseMessaging;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
Expand Down Expand Up @@ -270,15 +271,11 @@ private void subscribeToTopics(JSONArray topics, String registrationToken) {
if (topics != null) {
String topic = null;
for (int i=0; i<topics.length(); i++) {
// try {
topic = topics.optString(i, null);
if (topic != null) {
Log.d(LOG_TAG, "Subscribing to topic: " + topic);
//GcmPubSub.getInstance(getApplicationContext()).subscribe(registrationToken, "/topics/" + topic, null);
}
// } catch (IOException e) {
// Log.e(LOG_TAG, "Failed to subscribe to topic: " + topic, e);
//}
topic = topics.optString(i, null);
if (topic != null) {
Log.d(LOG_TAG, "Subscribing to topic: " + topic);
FirebaseMessaging.getInstance().subscribeToTopic(topic);
}
}
}
}
Expand All @@ -287,15 +284,12 @@ private void unsubscribeFromTopics(JSONArray topics, String registrationToken) {
if (topics != null) {
String topic = null;
for (int i=0; i<topics.length(); i++) {
// try {
topic = topics.optString(i, null);
if (topic != null) {
Log.d(LOG_TAG, "Unsubscribing to topic: " + topic);
//GcmPubSub.getInstance(getApplicationContext()).unsubscribe(registrationToken, "/topics/" + topic);
}
// } catch (IOException e) {
// Log.e(LOG_TAG, "Failed to unsubscribe to topic: " + topic, e);
// }
topic = topics.optString(i, null);
if (topic != null) {
Log.d(LOG_TAG, "Unsubscribing to topic: " + topic);
FirebaseMessaging.getInstance().unsubscribeFromTopic(topic);

}
}
}
}
Expand Down

0 comments on commit 22c7859

Please sign in to comment.