What exactly is Firebase Cloud Messaging? - android

I need to retrieve data from firebase database while app is in background or closed. For this, I have been thinking of using database reference in a service.
Instead of this, people recommend using Firebase Cloud Messaging. But what exactly is that?
How does is interact with the database? How do I use it for listening and retrieving data? There are very little explanation on these and firebase docs are too broad. Or maybe I just cant find it

But what exactly is that?
Firebase Cloud Messaging (FCM) is the latest version of Google Cloud Messaging (GCM), which is Google's Push Notification Service.
It allows developers to send data from their App Server towards the Client App. For your case, you may be able to send over the desired data towards your Client App, by integrating your Database with FCM.
How does is interact with the database? How do I use it for listening and retrieving data?
If you are using Firebase Realtime Database, you may choose to integrate with FCM in such a way (referring to #FrankvanPuffelen's answer):
Sending messages to devices based on inserts into the Firebase Database will require you to run a trusted process, typically on an app server that you control. This trusted process listens to the database changes and then calls Firebase Cloud Messaging to send the messages.
For an example of how to send messaging from a node.js script, see my answer here: How to send Firebase Cloud Messaging from a node server?
In summary, you don't use it to listen for data. You can however use it as the medium to send the data from your Database towards your Client App.

Since you are implementing Firebase for the first time, I'd recommend you to go through this and get a basic idea about it.
Broadly, FCM (previously GCM) is a Cloud Messaging service for your app. Most importantly, the Analytics and Realtime Database of Firebase are used.
Here is a link to their docs. Go through it for better understanding of Firebase and its implementation.

Related

database update notification in firebase for specific users

I am trying to create an android application and would like to use firebase database. As I read firebase allows instant messaging and also notify clients when database is updated. I need to create a database and when any database changes happen, related users needs to be notified only. Is that possible with firebase or should I use backend server for this purpose?
You can do it using the Firebase only.
What you needs are
Firebase Database (Realtime database/Firestore)
Firebase Cloud Functions
Firebase Cloud Messaging (FCM)
You should write two side codes:
Client side (Android)
Server side (Cloud Functions)
In Client side (Android)
You should register token. (To send a notification using the FCM, Token is needed.) You can do this easily (https://firebase.google.com/docs/cloud-messaging/android/client)
I recommend that you can store the token into the database/firestore too.
for example:
class User {
long id;
String email;
String token;
}
You may write the code to modify the database/firestore.
Implement receiving code (https://firebase.google.com/docs/cloud-messaging/android/receive)
In Server side (Cloud Functions)
Add some trigger to the database/firestore.
Get the token from the database/firestore
just send FCM message (https://firebase.google.com/docs/cloud-messaging/admin/send-messages)
You can get the sample code for Server side (Cloud Functions)
https://github.com/firebase/functions-samples/tree/master/fcm-notifications
Yes you can achieve this using Firebase Cloud Functions which:
lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your code is stored in Google's cloud and runs in a managed environment.
And with Firebase Cloud Messaging which:
Is a cross-platform messaging solution that lets you reliably deliver messages at no cost. Using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user re-engagement and retention.
So you can write a function in Firebase Cloud Functions which will trigger a notification every time something is changing in your database. Both documetations are very well explained.

Google cloud function and android application

I want to create social networking application whose features will be:
Authentication
Send Messages on newsfeed activity(visible to all the authenticated people)
when somebody comment/likes your message send notification
Followers
Followings
when somebody follows you send notification
Is firebase realtime database enough for this or I have to use firebase cloud function? or AWS dynamoDB or what would be the good combination to achieve desired functionality?
Thanks
You need to use Firebase Cloud Functions to send notification automatically on follow/comment/like.
All what you need is Firebase.
AWS is pretty much harder to init than Firebase.
You can see here some samples of using Firebase Cloud Functions.
This sample will help you to send notifications on follow/comment/like.

Android chatting app development

I want to make an Android app where there will be several clients and an admin.The app will be installed in client's device.Admin can be send message from computer to the clients and clients could be reply the message.
The admin could be also send notification to the all clients or to individual client.
Can anyone give me some suggestions that which technologies should i use to build such an app?
You need to build a backend for your app with a database to store user informations , messages etc... I suggest you to use a non-relational database because access to db values it's more efficient for this uses-case.
To make it easy you could try Firebase Cloud Messaging.
Here the official site
Firebase
You can use the Firebase which provides you a bunch of products like notification, authentication,cloud storage, cloud messaging, Notification. You can easily integrate this in your app by just following the documentation.

What does "app server in my own environment" mean in Firebase Cloud Messaging documentation?

I am having trouble understanding the specific meaning of "app server implemented in my own environment" as used in this documentation on how to send upstream messages to the "Cloud" using Firebase Cloud Messaging.
Context
The documentation is saying that for me to send upstream messages, I need my own app server that implements one of two connection server protocols in HTTP or XMPP.
The Reason why I am confused
My expectation is that if I use Firebase, I don't need to create my own server. All of the backend stuff is handled by them. So to me, when they say I need to create my own app server in my own environment, it is contrary to my expectation and understanding and thus makes me second guess the meaning.
What it is I am specifically confused and asking about
What exactly do they mean by app server?
What exactly do they mean by "in my own environment"?
Another way my two questions could be asked is:
Is an app server in this context meaning just a typical app server that I write on my own using something like Node.JS/Express.JS and host on something like Digital Ocean? and/or
Is it something I need to do with other Firebase/Google Cloud products (eg Hosting or App Engine)?
Or could my implementation of the RealTime Database feature on my app be considered an "App Server" as it serves my app with data.
What I have done so far
Reading through every single documentation on Firebase relating to Cloud Messaging and browsing around Google.
I have had a solid read of what questions to ask and what to avoid. I am mindful that this question could be something with lots of varying and all correct answers so apologies if that offends one of the rules. But I have come across this question on Meta which suggests that asking for clarification on documentation is OK for SO.
Is an app server in this context meaning just a typical app server that I write on my own using something like Node.JS/Express.JS and host on something like Digital Ocean?
Exactly.
Is it something I need to do with other Firebase/Google Cloud products (eg Hosting or App Engine)?
Depends on your use-case. But for Firebase Cloud Messaging, when all you need is to send Downstream Messages, you don't need an App Server. You can just make use of the Firebase Console. If you need to send Upstream Messages, then you have to implement your own App Server.
Or could my implementation of the RealTime Database feature on my app be considered an "App Server" as it serves my app with data?
Not exactly. The Firebase Realtime Database stores the data you need, but the App Server needed for FCM is something that can process requests (Send (Downstream and Receive (Upstream)).
App notifications are sent by Firebase Cloud Messaging server. To send these notifications you will have to tell to which device notifications have to be sent.
So you will have to send the FCM Client ID from your backend server (Node.js, PHP server). You will get the FCM client ID when you integrate Firebase into your app. You will have to store the FCM client ID in your backend server like during registration of a user.
To send a notification to a device retrieve the FCM Client id from your backend server and send it to the Firebase cloud messaging server and it will check if the client id is valid and trigger a notification.

How can i send a string from one android to another over internet

I want something similar to Facebook messenger and
I don't have much knowledge about web servers,can i use them?
It should be like
I accept on String from user and then upload it to my server and program the server to send it to other device and the other device gets notified by a background service
To create something similar to Facebook messenger, you could do a lot of things.
Just to start, in my opinion, a Serverless service. Firebase could be your solution or AWS (or any other service). It has a Push notifications and database where to store that Strings.
Firebase Cloud Messaging
Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost.
Using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user reengagement and retention. For use cases such as instant messaging, a message can transfer a payload of up to 4KB to a client app.
Firebase Realtime Database
The Firebase Realtime Database is a cloud-hosted database. Data is stored as JSON and synchronized in realtime to every connected client. When you build cross-platform apps with our iOS, Android, and JavaScript SDKs, all of your clients share one Realtime Database instance and automatically receive updates with the newest data.
Other way is open a socket in your Android app and handle all the events. I recommend you Socket.io to do that.
You could use node.js in your server to create a socket server and use the Android client.
http://socket.io/blog/native-socket-io-and-android/

Categories

Resources