Reputation:
I am trying to get Push Notification w/GCM in my PubNub app:
Here is what I am doing :
Subscribe to PushNotification Channel :
var regId = getDeviceRegistrationId(). //This was from GCM register response
pubnub!!.addPushNotificationsOnChannels()
.pushType(PNPushType.GCM)
.channels(Arrays.asList( pubnubChannelID+ CHANNEL_TAG_PUSH))
.deviceId(regId)
.async( object : PNCallback<PNPushAddChannelResult>() {
override fun onResponse(result: PNPushAddChannelResult?, status: PNStatus?) {
Timber.d("PNPushAddChannelResult "+!status!!.isError)
}
});
In Pubnub console, I put in a valid GCM api key
I am publishing the Message as below to the Channel registered above :
{ "pn_gcm": { "data": "A Message" }, "pn_apns" : { "aps": { "alert" : { "loc-key" : "MessageAlertKey", "loc-args" : "none"} } } }
The documentation at : https://support.pubnub.com/support/discussions/topics/14000006344#latest is only marginally useful.
What am I missing from receiving a GCM Push Notification on android device with Pubnub?
Appreciate any help.
Thanks
Upvotes: 1
Views: 177
Reputation: 4738
NOTE: the following content can be found in this PubNub Support KB article, but there is a Stack Overflow policy to not reply with a simple link. So I am pasting the content here. I wrote the original, so it's not stealing ;)
When you configure and implement FCM into your PubNub application, you may not see the push notifications that you are sending. Before you do any PubNub mobile push troubleshooting, please be sure that you are sending, and receiving, the intended FCM type.
NOTE: The following comes directly from the Android FCM docs: With FCM, you can send two types of messages to clients:
Following the above, it could be that your code in your app is pulling the wrong message type or you are sending the wrong message type. For example, you could use one, the other or both of these message keys in your FCM (formerly known as, GCM) message payload: data
or notification
.
{
"pn_gcm" : {
"notification": {
"title":"Portugal vs. Denmark",
"body":"great match!"
},
"data" : {
"body" : "great match!",
"room" : "PortugalVSDenmark"
}
}
}
You only need either data
or notification
(perhaps both depending on your use case) but it does matter if you only send data
because your code is explicitly responsible for displaying the push notification, whereas notification
will be automatically displayed by Android.
Upvotes: 0