The following provide some details on how to add the Firebase Admin SDK to your server to send Firebase Cloud Messaging (FCM) messages to android devices. I have implemented the following using Java with the Spring boot framework, check the documentation for more details .
I will assume you have completed the following before proceeding: connected your application to firebase.
According the documentation the Admin SDK lets you interact with Firebase from privileged environments to perform actions such as reading Realtime Database, programmatically send Firebase Cloud Messaging messages and more.
- Make sure that your server runs the following: Admin Java SDK – Java 7+ (recommend Java 8+), check the documentation for other SDK. The following is also supported Node.js, Python, Go and .NET read the guide for more details.
- Set up a Firebase project and service account
- Add the SDK: install the SDK for the language of your choice in my case java with Maven as build automation tool (Add the firebase-admin dependency to your pom.xml file).
- Authentication using service account: Generate a private key file for your service account (check the documentation for more details), download the JSON file (containing the key)
- Initialize the SDK using the key generated
- At this stage your App server should be able to connect to Firebase.
Once you have successfully completed the steps listed, your app server should be connected to Firebase.
- Device registration: when user installs the app
- Generate device token: FCM will assign a unique token to each device
- Upload token to back-end: this allows you to send FCM notification to a specific user depending on your business rules.
- Send Push notification from trusted application server to FCM with Token (s)
- Delivers notifications to registered devices