Use FCM with another database - android

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.

Related

Sending push notification to a specific user in cloud function FCM

Please note that this question is not about getting device token on client side.
I am very new to react-native and firebase and I want to implement push notication service of FCM. What I am planning to do is to send a notification to particular device using its device token on my nodejs app server or cloud function( not through console). But as I have found, FCM doesn't provides any API to accrss token by username. Suppose I want to send notification to user X( for the time being, suppose that one user signs only on single device). Now using the function sendToDevice(), I can send the message to a specific device. But how would I know the device token of user X. Do I need to store tokens in the firebase database by myself? Or can I get along without storing FCM tokens?
Please guide me because firebase docs aren't clear about this.
Save the device token for a particular user in DB and then you can use fcm-node npm in which there is a simple function to send a push to a particular device token.
You also need to use the FCM server key which you will get easily on the firebase console.
FCM doesn't offer a way to associate device tokens to individual users who might be using your app from multiple devices. You will need to write code to associate a device token to a user account by sending that token to your backend, along with the user's ID. Only then can you collect FCM tokens for that user, and message them on any of their devices.

How Android GCM works?

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

Send Firebase Notifications from android device

I just switched my app over to firebase 2.0 from parse. Basically I have an android app (main app) built for the general public to use. Then I also built a second app (manager app) that only I and a few others have access to which is used to update the content of the main app. Now I am adding in notifications which work fine when I send them from the firebase console, however, is it possible to send them from the manager app to the main app? If not, what would I need to do in order to send them from somewhere other than the console (I don't want anyone else to have access to the console but would like them to be able to send notifications.) Thanks!
Seems like you are looking for device to device messaging. This is not currently supported by FCM, so you will need some type of server.
The server could implement XMPP in which case it can be a relay, upstream messages from admin client will be converted to downstream messages to non-admin clients.
The server could watch the Firebase Relatime Database and then the admin client could write something to the database and the server watching the database could then take action and send notifications to non-admin clients.

Push notifications from server-android

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

Android application that sends data to all application holders

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

Categories

Resources