Skip to content

This is an Android library for Firebase Cloud Messaging (FCM) that showcases how to register your Android application to receive notifications and manage the reception of messages

License

hypersoftdev/fcm

Repository files navigation

FCM

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.

Getting Started

Step 1

Add firebase to your Android App

Note:

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 dependecies

Classpath in project level build.gradle

    classpath 'com.google.gms:google-services:latest-version'

or latest

    id 'com.google.gms.google-services' version 'latest-version' apply false

Plugin in App level build.gradle

    id 'com.google.gms.google-services'

Dependencies

no dependencies required

Step 2

Add maven repository in project level build.gradle or in latest project setting.gradle file

    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
    }

Step 3

Add FCM dependencies in App level build.gradle.

    dependencies {
             implementation 'com.github.hypersoftdev:fcm:1.0.4'
    }

Step 4

Finally intialize Firebase and setup FCM in application class or in your "MainActivity"

    SonicFCM.setupFCM(this, "YourTopicName")

Remove

If you want to stop receiving notification from the subscribed topic simply call.

    SonicFCM.removeFCM("YourTopicName")

Send Data Message using the HTTP protocol with POSTMAN

Step 1

You have to copy Legacy Server Key from Firebase Console > Project Settings > Cloud Messaging

Note:

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 issue then First Enabled "Firebase Cloud Messaging API" from Firebase console.

alt text

Step 2

  • Open Postman, click on Enter request URL textbox, enter firebase url
 https://fcm.googleapis.com/fcm/send
  • Then change request type to "POST"
  • Now to 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" than select "Raw" and add value as JSON object like below
{
      "to":"/topics/YourTopicName", 
      "data":
      {
                "title": "My Application Titile 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"
      }
  }

Postman Screen

Header

alt text

Body

alt text

Note

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 promotion)

LICENSE

Copyright 2024 Hypersoft Inc

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.

About

This is an Android library for Firebase Cloud Messaging (FCM) that showcases how to register your Android application to receive notifications and manage the reception of messages

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages