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?
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.
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.
Related
I have a script on server which sends sms or telegram messages to users. I want to send sms when user is offline and send telegram message when user is online.
Is there any way to detect whether android user is online or not from my server (maybe sending request to already running some app?).
Note, users are willing to share some credentials if necessary.
Android OS version: Api 21+
Well, I created my own app.:
I used firebase cloud messaging to send notification (as it is lightweight and based on event-driven model) to devices from my app server. Byw, telegram uses gcm which is younger brother of fcm.
I send only data messages (only payload) to my app from my app server so that I can get my app notified about notifications even if it is in background.
When app receives notification, it sends upstream message so server knows that user has received message.
If server doesn't receive response from user within 5-10 seconds, then user is most likely to be offline.
I have two version from my app one for the customer and one for the client I need to send push notification to the specific client(in client app) when the customer take an specific action (in customer app).
I know that I should use Firebase Cloud Messaging as it's a new replacement to GCM, but I can't figure out how I can do this in both server side and client side.
you have a lot of options here!
let's start with the server side:
you have two options HTTP or XMPP, HTTP is a one way connection XMPP is two way.
for your app you will need XMPP for upstream and down stream messages
check there Guides it's really great: Server guide
there is also a Java and Node.JS Admin SDKs but i don't know much about.
but there is a great Tutorial which describes the whole proccess if you go for Node.js
So what happens is:
when a device sends an upstream message
Firebase will forward it to your server
Your server should handle the message and send it to the other device through Firebase cloud messaging
you can implement a server-less app using real time databse but you will not receive message in background, but when the receiver app is running it listen to databse changes and send notification to user
you can also make a server listens to databse changes "instead of receiver" and take actions upon it"send a message to the other device"
Edit:
with the new cloud function feature you can now use it to send notifications to users based on database events,
so you can add your message to database in a class
and make a cloud function to listen to this class write events
and whenever a message saved to this class, it sends it to desired
receiver
so now you don't need an external server to send notifications to
devices
check this cloud function sample, it's an example of sending notifications based on database event.
I am trying to make a simple messaging app that has a mysql and php server with an android app. My back end revolves around mysql to store and php to communicate from the database to the device and vise versa.
Now, what I am trying to accomplish is this: sending device->GCM->target device.
What I had in mind was that the database I created stores the gcm Id for all user. That way, when a user wants to send a message, their app sends a message to my database to be stored and retrieves the targets gcm Id and then sends the targets gcm id to the gcm servers to create the push notificiation. When the target receives the gcm message, it sends a response to the database to receive the actual sent message.
Is this possible, and how would I go about doing this?
I already have a gcm receiver implemented from here:
https://github.com/codepath/android_guides/wiki/Google-Cloud-Messaging
No. Don't do it.
For any internet connected device (server or mobile) to request a push to a device, it needs to send a POST request to the GCM address (https://gcm-http.googleapis.com/gcm/send) passing the server API key and the device GCM reg id which should receive the message. And having any of those values available on a device is a security risk for your application.
Having your registration ID, means ppl could easily "copy" your ID and start sending messages from their servers on your behalf.
The GCM device registraion ID, means anyone could start spaming your users, and you certainly don't want that.
You could look into GCM Upstream (https://developers.google.com/cloud-messaging/upstream) but that only means your client code will be easier, as it's as simple as calling gcm.send(String);, but you still have to handle that on your server application.
The correct way is to have on your server a table that maps userId with gcmRegId and have devices send to your server messages to their desired userId. Your server should process one device "send" message and create a push to the other device. That logic should be fairly simple on the server side, after you already have a whole chat application developed.
I'm very new in meteor and I just made a simple app that show news (text) for a school, the problem is that no one knows when they write something new because the app doesn't have notification. I can't figure out how to use raix:push or richsilv:cordova-notifications because the test of raix:push didn't work in my device (android) and richsilv:cordova-notifications just work with android and I couldn't make it automatic. Saying "automatic" I mean "when the mongo collection is updated a notification is sent"
I think you may need to set up push server for sending notification to Android client.
Google is providing such option, where client app has to register with GCM server. On successful registration, google will give reg Id, which has to be stored in DB.
From your server make HTTP request to GCM server with Reg Id and message. GCM will deliver the message to appropriate device.
Please refer https://developers.google.com/cloud-messaging/gcm
Can we send the message from Android Device to GCM server?
I am implementing the Total GCM functionality to get message from server and it works fine.
Now i want to save that message response right now i am using separate webservice to store response to server,
Can i do that using GCM instead Webservice?
No you can't. You need to create XMPP server for that. You can see brief answer here
You can check example of chat here
GCM is only a system to deliver messages to registered devices. It is not responsible for any other activity.
If you want to store data, that will need to be on your registered device or your web service.