I have this application that notifies its registered users on updates about something...but the things is that I don't know how to send that data as a notification to all of the applications users
To send data as notifications to users you could use Google Cloud Messaging (GCM).
With GCM users can automatically register with you when they first run the application. You save their unique id in a database somewhere and then you can use these ID's to send messages (data) to the Google servers who will then push this data to the Android devices.
To read more about GCM and how to implement it check out the Android Developers site: http://developer.android.com/guide/google/gcm/index.html
Related
I am developping a mobile application that must implement push notifications. Documents are stored on a SQL database, and people should be able to edit these docs after downloading them offline, then the modifications should be saved in the SQL Database once the phone is online again. People should be able to receive notifications when the app is closed.
I heard that I need push notifications, and for android there is Firebase Cloud Messaging (FCM). But is it possible to use FCM with my SQL database ?
All tutorials in the docs only speak about connecting the app with Firebase
For your project you need a server with your API, SQL Database... and a push notification server that ask FCM services to notify your registered devices.
FCM works like that :
You add the FCM plugin in your Android/iOS app, then when you launch the application it will ask FCM for a unique token associated for your device and this app. You will store that unique token in your push notification server, I advise you to associate it with a user identifier or one thing that you will use to identify the device to notify.
When your first server (with the APIs and the Database) did some action and you want to notify a device :
The server will ask your push notification server to notify a list of devices that you will probably determine with the user identifier like I said earlier, then the push notification server will find the associated tokens and send all of the pre stored tokens to FCM with the notification content you want to send, you can also send parameters that will be used to do special actions in your mobile app.
Finally FCM will notify your devices :)
Hope it helps.
I was wondering how android push framework is able to distinguish data recieved via GCM and forward it to the appropriate android application for which it was intended ?
Can anyone let me know how it is done ?
You question : how android push framework is able to distinguish data recieved via GCM and forward it to the appropriate android application.
From your question it looks like you willing to know about data
workflow & Client Server architecture that exists in applications
which are using the GCM service.
As per google’s documentation “Google Cloud Messaging for Android (GCM) is a service that helps developers send data from servers to their Android applications on Android devices”. GCM is a service provided by Google for developer that helps developer to send data from server to any number of Android devices.
Simplified Application Specific Work-flow:
The push notification can be broadcasted either to the mass audience
or a select set of users. Mass audience is targeted when the
notification has to be sent about a marketing campaign. A subset of
users are targeted when a personalized information has to be sent.
The below steps explains how push notification works on android devices:
First android device sends sender id, application id to GCM server
for registration.
Upon successful registration, GCM server issues registration id to android device.
After receiving registration id, device will send registration id to our server.
Our server will store registration id in the database for further use.
Whenever push notification is needed, our server sends a message to GCM server along with device registration id (which is
stored earlier in the database).
GCM server will deliver that message to respected mobile device using device registration id.
This can also be understand using following figure
An Example Workflow:
So, from above images it easy to understand that whenever the android
application is first installed by the user, then it registers itself
to GCM server, and obtains unique GCM ID, then it's our Host servers
responsibility to keep this newly registered Registration ID of the
android user into Database, and then it will be used whenever server
side application willing to send the message to that particular
android user.
So, let us consider one case; suppose an Server wants to send Some data to Android User, which has already registered it's GCM ID 1234567 when it's first time installed, and as it's in the server's database the server application will fetch it from DB, and simply make a HTTP POST request to the GCM server in JSON format, which will have registered user's GCM ID along with the data to send , in same way the GCM Server has the record of all the Registered GCM/Android Clients, it directly forwards that message to the intended android user, and android app in user's phone will raise and Notification alert, to indicate an push notification has arrived.
Hope This answers an question!
GCM stands for Google Cloud Messaging.
Every push notification receive on any Android device is sent by the GCM only.
sender -> GCM -> Android Device
when sender sends an push notification then it goes to GCM. GCM receives that push and forward it to particular Android Device by its Unique device id.
GCM can't deliver Push without Unique Device ID.
while implementing push notification there are two important things, application key and server key ... these are unique Keys.. using these keys GCM identifies the application to whom push notification is related
I have an android application where a user can insert data into web sql server. I want all the users to receive push notifications when someone inserts a row into database. How to implement.
You can use Google Cloud Messaging (GCM)
Google Cloud Messaging (GCM) for Android is 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. The
GCM service handles all aspects of queueing of messages and delivery
to the target Android application running on the target device, and it
is completely free.
For more info on how to use it, refer to developer.android.com
Try this tutorial (or the official documentation) for specifics, but in overview you maintain a list of registration tokens for your users, and send the list of tokens for users you want to get a notification to Google and the send it out. Google will tell you afterward if any of those tokens are now invalid--those should be removed from your system at that point.
http://www.tutorialspoint.com/android/android_push_notification.htm
I'm trying to use GCM to establish communication between some users. They should send to each other their GPS location. Is it even possible? There is a subscribeToCloudMessage method but I don't know whether it will be useful or not.
Info: Server works fine (Google app-engine) with all the required keys.
It's possible for one app to send a message to another app via Google Cloud Messaging if the sending app knows the registration ID of the recipient app. Usually when a app register to Google Cloud Messaging, it sends it's Registration ID to a server, and that server sends GCM notifications. If you want the app to send the notifications directly, you must send each device (where the app is installed) the Registration IDs of other devices that it needs to send messages to.
1- let's Say I've Create A GCM Application In A Google Apis Console ...
How Can I List And View All The Devices Are Registered In My Application Cloud
To Perform An A Random Action Like Send A Push Notification to them ?
2- Should I Create A database to Store The Registration IDs Returned By Registered Devices
If I Use My Own Server Like (Asp.net)
How Can I List And View All The Devices Are Registered In My Application Cloud
There is no GCM call to do this. Your app needs to tell your server the IDs to use for GCM broadcasts to that app on that device, and your server then needs to store that data somewhere.
Should I Create A database to Store The Registration IDs Returned By Registered Devices If I Use My Own Server Like (Asp.net)
A database would seem like a fine choice.