0

Well I've heard about Google Firebase Cloud notifications. I want to add it to my Java server and to my Android app. I tried to understand how to send info from my server with the Firebase Cloud to clients, but there were so many terms like tokens and building a notification.

Can someone just write to me "in a nutshell", how can I add this Firebase to my Java server and send a simple notification to a client?

AL.
  • 36,815
  • 10
  • 142
  • 281
Eldar Azulay
  • 271
  • 1
  • 3
  • 17
  • Your java server creates a Firebase "listener" that connects to a json node in your firebase string. Whenever there is an update inside the subtree rooted at the node on which you are listening you'll get a callback notification of the change. You can add multiple listeners at varying points throughout your json tree. Clients can also add listeners to the parts of the json to which the client has read permissions. – mba12 Feb 27 '17 at 21:14
  • @mba12 Actually what I want to do is just send a notification to the client by changes on the server, the server decides when to send the notification. Why would I use the update at the node? I am afraid I don't understand you well. – Eldar Azulay Feb 27 '17 at 23:32

1 Answers1

3

This post is a bit broad. But I'll try to explain it in the simplest way I can. But I strongly suggest that you just watch the Getting Started with Firebase Cloud Messaging on Android - Firecasts vid.

You can send FCM Notifications by sending HTTP Post Requests (through your App Server) to the FCM endpoints that contains the Message Payload -- data that you want to send. This post might be useful for you.

This payload is then sent from the FCM Server towards the specified (Android) client app(s) that are configured and have implemented the client-side handling of messages from FCM. See the Setting up an FCM Android Client app for more details.

Upon registration, each client (i.e. app instance) will generate a Registration Token that you use in your payload, to specify which user(s) are going to receive the push notification.

On a simpler note:

  1. App Server sends payload.
  2. FCM Server receives and processes the payload, determines if the App Client is available, then sends the payload.
  3. Client App receives and handles payload.
Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281
  • And how can I implement the firebase sdk into my java project? – Eldar Azulay Feb 28 '17 at 06:45
  • Which SDK? You simply just have to send POST requests from your App Server. No SDKs needed. – AL. Feb 28 '17 at 07:36
  • But I saw that firebase has java sdk on their website. If I don't need any sdk, how do I send those post reauests? To where? And where is that firebase node stored? – Eldar Azulay Feb 28 '17 at 07:40
  • Can you point out the link to the SDK? You send it like a usual POST request towards the FCM endpoint (as I mentioned above). Here's a simple example -- http://stackoverflow.com/a/39970818/4625829 – AL. Feb 28 '17 at 07:45
  • Ohhhh I see, I didn't know that. Thank you very much, you helped me so much right now! – Eldar Azulay Feb 28 '17 at 07:47
  • I have one more question. How do I send a message to a specific client and register his preferences on my server using his unique token? – Eldar Azulay Feb 28 '17 at 10:07
  • That question is *also broad*. :p But to give you an idea, to send push notifications to only a specific user, use the `to` parameter. For retrieving the references part, you'd have to make your client app send those details towards your App server on your own (like a POST request or something). – AL. Feb 28 '17 at 10:22