4

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?

Ivan
  • 34,531
  • 8
  • 55
  • 100
Newbiee
  • 592
  • 6
  • 22
  • By *the app is offline* do you mean the app is in ***stopped/killed*** state? – AL. May 26 '16 at 00:59
  • yeah!! at that time how to notify the user about the message just like whatsapp – Newbiee May 26 '16 at 03:17
  • It's impossible to receive a notification for your app when it's totally stopped/killed. I mentioned it in my [answer](http://stackoverflow.com/a/37429495/4625829) for this [post](http://stackoverflow.com/q/37357745/4625829). It's possible if it's only *closed*, because the background services could still be running. – AL. May 26 '16 at 03:21
  • @McAwesomville then how to notify user about the new message, when he is away? i am thinking about trigger on the ofoffline table of openfire. – Newbiee May 26 '16 at 06:58
  • Hi have you find the solutions? – nitesh Dec 16 '16 at 08:51

2 Answers2

1

I'm facing this problem too.I'm solving this as folowing steps:

  1. Develope a WebService (ASP or PHP or ...) with a database that will contains users FCM-TOKENS per JID
  2. Developing FCM on android devices and send TOKEN whent it refreshed to my WebService and save it in db.
  3. Activate "CallBackOnOffline" plugin in openfire. (that sends POST request with a JSON to defined url when a message received but recipient is UnAvailable)
  4. 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.
  5. Now fetch the FCM-TOKEN from my web service db and send a request to FCM containing message body and title.
Mahdi Moqadasi
  • 2,029
  • 4
  • 26
  • 52
0

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.

  • i am talking about when app is running the message gets delivered by xmpp. but when app is not running/ not in background, then i would like to send push. i know how gcm works, but i dont know how to fire that trigger at server itself – Newbiee May 25 '16 at 10:15