I am creating android chat app using PubNub.I am using GCM push gateway with pubnub to publish messages to channel. Let's say User A and User B start a private chat.
case 1 - A and B is connected to internet
App is working perfectly. If "A" sends a message to B, "B" receive it regardless the app is in foreground or background.
case 2 - A or B is not connected to internet
Lets say "A" is connected to internet and "B" is not. "A" publish a message to "B".
Can I know, what will happen in Pubnub-end and GCM-end in this case-2?
This is the way I am publishing the message.
PnGcmMessage gcmMessage = new PnGcmMessage();
try {
gcmMessage.put("delay_while_idle", true);
}catch (Exception e){
e.printStackTrace();
}
gcmMessage.setData(messageObject);
PnMessage message = new PnMessage(
pubnub,
channel,
callback,
gcmMessage);
try {
message.put("pn_debug", true);
message.publish();
} catch (PubnubException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
I am still getting familiar with creating real time messaging applications. So I don't know what is missing there. So please guide me on handling this issue.
The PubNub Mobile Push Gateway allows you to use GCM (Android), APNS (iOS) & MPNS (Windows Phone) as a fallback mechanism for your mobile apps to receive messages when your app is not actively running and connected to PubNub.
This PubNub article, Sending APNS and GCM Messages to Subscribers and Mobile Push Notifications Services in One API Call , serves as a mini-FAQ for PubNub mobile push notifications. There is a short video at the end that serves as a summary of this article.
If the app that is publishing is not connected to the internet (via cell or wifi), then the publish will fail. Your app (not just the device) must be running/active/connected (in foreground or background) to the internet in order to be connected to PubNub and publish messages.
If the subscriber app is not connected to the internet, then your app will not receive the published message via the subscribe
callback (the PubNub realtime message).
If the device has some sort of connectivity (cell or wifi) so that the GCM service (this is not PubNub) can send push notifications to the device, then the GCM message that was included in the published message will reach your app.
See also:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.