Check if android device is online from server - android

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.

Related

implemented FCM for the Client Project (app on android device). How can I use the Server for sending Notifications

we created a Chat application with a Client and a Server project.
Clients can send messages to the server and the server and the server forwards it to other Clients (like a Chat application should do)
FCM is implemented in the Client project. Users can send Notifications to each other.
How can I use the Server for sending Notifications? Can I just write the Code for sending Notifications in the Server project (Server does HTTP Request with User token etc.).
Idk about that because I think the project should be somehow registered to FCM to use the services.
I only find tutorials about sending Notifications from App to App, not from Server to App.
For example in this scenario:
User installs app, then creates account and gets confirmation email from the server
, then clicks on confirmation link (app is clossed or in background)
, then gets notification that the account is ready
I think this is not possible with using FCM only in the app project

Android: Developing a Chat app

I am developing an one-to-one chat app. The problem is how should I keep all clients and server in sync? There can be multiple cases when the message fails to send from the client, or it is not received by the client.
Right now, I am using a pub sub service and GCM. Whenever user is using the app, I subscribe to a unique channel to receive messages and use api to send message. Also, through pubsub I am maintaining user online status.
Whenever app goes into background, pubsub disconnects and user goes offline. In this case GCM is used to deliver messages to the client.
This systems is working fine. But rarely there are messages that are not delivered to the client.
Can this be improved to assure message delivery ?
Here is a good tutorial.
with client side and server side codes...

Sending Notification to user when user is offline in android using XMPP

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.

GCM between User to User from same Android App

I would like to implement GCM in my Android app:
One Android app
Registered- U_user and another M_user.
I have Google Sign In in my app thats works fine with JSON and GSON and local MySQL database server with tomcat-server restutil to keep storing Gmail login users.
So, I want to send a notification from U_user to M_user.
U_user does a registration that has been pushed to M_user.
How can I do this?
I am assuming you mean the same Android app installed on different phones (U_user's phone and a separate phone for M_user).
To quote a section in the docs:
To make sure that messages go to the intended user:
Your app server can maintain a mapping between the current user and the registration ID.
The app can then check to ensure that messages it receives match the logged in user.
What this means is that you can send messages to another user through GCM. To let the app server know what to send to M_user, let U_user send an upstream message to your GCM app server (only possible in app servers using XMPP - see here). Alternatively, you have the option to do POST requests to your app server via HttpUrlConnection (can work on both XMPP- and HTTP-based GCM app servers).
Regardless of which method you use, specify in these messages to the server that you would like to send a message to M_user.

push notification to get device location

Hi i want to use push notification on android device and get device location for more information
I want to write application for android that when server want to get android device location push a notification timely to the device and the application on the device send device location to server timely.
I can't use Cloud to device messaging service because this service need that user first online and after user is online send server notification with C2DM service!.But i want to send notification to device and get device location any time server wants.
For any sort of push notification to be made possible, your client will need to be online. An offline client cant accept push notifications until it is online.
A C2DM push can be initiated by the server. No need for client to start it. The server just needs to send a message to the C2DM server and notification will be sent.
What you basically need to do is, on receiving the notification from C2DM server, make your C2DM base receiver call a function, which retrieves the clients location data using LocationManager and send it to the server.
EDIT for MQTT:
i havent done this much myself but it can be used for push service
You need:
an MQTT broker which runs on the server side, like the mosquitto broker which is Open Source.
an MQTT client library which you include in your Android app, enabling your app to connect, subscribe, and publish messages. refer this http://mqtt.org/software
to come up with a way of uniquely identifying users or devices, and then use that as a topic so that you can individually publish a message to one device.

Categories

Resources