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.
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 questions related to Android Push Notification System:
What is the working principle of this system? The client sends its own IP to the Google Cloud Messaging Service (for example when it switches its own IP)? So it a sort of pooling?.
How do you know that Google Cloud Messaging Service "looks into" the content of the notification message (created in the server and dispatched to the client)?
Answering the question about how GCM service contacts the client, the GCM client contacts GCM to create the connection. You are correct that device addresses change as the device disconnects and reconnects so GCM cannot initiate the connection from the server side.
This connection is maintained as much as possible and is not created for specific messages.
The registration id identifies the device and app and allows GCM to route the message to the device, if it is connected. If it is not connected, GCM needs to wait until the device reconnects.
What is the working principle of this system? The client sends its own
IP to the Google Cloud Messaging Service (for example when it switches
its own IP)? So it a sort of pooling?
I'm adding an image here describing how GCM works.
This is a step by step presentation. You need to get the push registration ID first when your application launches. So if you've a backend server to send some push notification in your application, you need to pass the registration ID to your backend server. So when you need to send a push notification, your backend server will send the push directly to GCM with the targeted registration ID. GCM manages to push the notification in your device when your device comes online.
So this is not any kind of pooling. The only thing GCM needs to know is the registration ID of your device when it comes online and tries to communicate with GCM. Once your device is registered, GCM sends the push notification using that registration ID.
How do you know that Google Cloud Messaging Service "looks into" the
content of the notification message (created in the server and
dispatched to the client)?
This question is not very clear to me. As far as I have understood, you wanted to know how GCM understands to whom it needs to send the push notification when the notification is coming from your backend server. If this is your question, then I think I have answered it already in the previous section of my answer.
GCM doesn't need to look into your notification content to know the destination of the push notification. As I said earlier, when your application launches, it requests for a push registration ID from GCM and when it receives an registration ID, you might have to pass the registration ID by calling a service of your backend server. The server then knows to whom it might send some notification.
So, when its time to send a notification to your client application, the backend server sends the notification to GCM with the registration ID you sent to your backend server earlier. GCM then handles sending the push notification to the client when the application comes online.
Hope that helps!
I wanted to know how to address a specific android phone to send push notifications as the google's gcm is slow and also as i want to learn how to send push notifications without google cloud messaging and to build my own api for sending push notifications to other platform devices .
I'm not sure how to address an android phone whether by its IP address or keep a socket for listening at a port.
Please help!
You not need to use ports or some listening mechanism to build. Use the Google's GCM way.
You need to build a service that will periodically check your server for any massages to get (fetch) for your specific device (keep a self created unique id with each device and registered the device on your the server by that id). Actually this is not pushing. but this is what happening in the GCM server also. When you put some massage for some specific device to your server(it is the pushing) the device will grab that by the service running on it.
simply you have to create a server by yourself (like GCM server)
Then you have to create a service to run on mobile to check updates on your server (like android play service)
Am working on an application in android that does the following. A part of the application is that the administrator can send universal notification to everyone registered to that application. I want this service to be in a way that the administrator uses his wireless to send the message to cellular gsm service. Now i was thinking it that is possible in android. How can i possibly do that?
A part of the application is that the administrator can send universal notification to everyone registered to that application. How can i possibly do that?
You can use Google Cloud Messaging for Android. It a service that allows you to send data from your server to your users' Android-powered device, and also to receive messages from devices on the same connection. You can send messages( or notifications) to all the Android users of your app. Each user would have a registrationId which would be unique for each user ( if you register them). That ID can be used to send messages to all your app users.
P.s: By wireless I am assuming internet.
I have some doubts with Meteor server? Whether will it send push notification like Google C2DM? I mean this server can send push notification whenever we are puling data to server or it will pushes in a periodic manner? How can this server identifies the devices? Is there any device token like C2DM?
The Meteor server will push the messages as soon as you add them to the queue. If the clients are waiting for a push message (they are connected) they will receive the message (almost) instantly.
You can't identify clients, Meteor works with queue names, so you should use an unique queue name for each device (like hashing unique device or user info) I don't know how C2DM works, so I don't know the differences.