FCM is a Firebase Cloud Messaging Android library that demonstrates registering your Android app for notifications and handling the receipt of a message. Example Send Data Message using the HTTP protocol with Postman.
Add firebase to your Android App
After completion of step one, your project should have a google-services.json file added to the root of your project along with the classpath, plugin, and dependencies
classpath 'com.google.gms:google-services:latest-version'
or latest
id 'com.google.gms.google-services' version 'latest-version' apply false
id 'com.google.gms.google-services'
no dependencies required
Add maven repository in project-level build.gradle or in the latest project setting.gradle file
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
}
Add FCM dependencies in App level build.gradle.
implementation 'com.github.orbitalsonic:SonicFCM:2.0.1'
Finally, initialize Firebase and setup FCM in the application class or your "MainActivity"
SonicFCM.setupFCM(this, "YourTopicName")
If you want to stop receiving notifications from the subscribed topic simply call.
SonicFCM.removeFCM("YourTopicName")
You have to copy the Legacy Server Key from Firebase Console > Project Settings > Cloud Messaging
Firebase has upgraded our server keys to a new version. You may continue to use your Legacy server key, but it is recommended that you upgrade to the newest version. If anyone else is facing any issues then First Enabled "Firebase Cloud Messaging API" from the Firebase console.
- Open Postman, click on Enter request URL textbox, enter Firebase URL
https://fcm.googleapis.com/fcm/send
- Then change the request type to "POST"
- Now click on Header and add two params "Content-Type" and "Authorization"
Content-Type: application/json
Authorization: key=AAAAp5XtBPY:APA91bG_fypMd0j... //FCM SERVER KEY
- Now click on "Body" then select "Raw" and add value as JSON object like below
{
"to":"/topics/YourTopicName",
"data":
{
"title": "My Application Title is Here",
"short_desc": "My Application Short Description is here",
"icon": "App Icon link is here",
"feature": "App Feature Image Link is here",
"package": "Promotional app package name is here"
}
}
These Three items are mandatory for notification
- title
- icon
- short_desc
These Three items are optional for notification
- long_desc
- feature
- package (in case of other app promotions)
Copyright 2022 OrbitalSonic
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.