问题
I implemented an Android chat application using Smack client with XMPP server. Everything works fine when the user is online, now when the user is offline (the app is not in running state). I would like to push notification using GCM.
Is there a way to achieve that, and is there a way that we can manage our server itself to take care of that?
回答1:
You can send push notification any time the user is online or not but the device has internet.You have all devices device tokens so when you send a message to a particular user, use his device token and send push notification.
回答2:
I'm facing this problem too.I'm solving this as folowing steps:
- Develope a WebService (ASP or PHP or ...) with a database that will contains users FCM-TOKENS per JID
- Developing FCM on android devices and send TOKEN whent it refreshed to my WebService and save it in db.
- Activate "CallBackOnOffline" plugin in openfire. (that sends POST request with a JSON to defined url when a message received but recipient is UnAvailable)
- Set "plugin.callback_on_offline.url" in "Service Properties" to my WebService. So the message and the jid will be sent to my web service.
- Now fetch the FCM-TOKEN from my web service db and send a request to FCM containing message body and title.
来源:https://stackoverflow.com/questions/37433741/sending-notification-to-user-when-user-is-offline-in-android-using-xmpp