Feb 1, 2024

Sami Abboud

Guide to integrate Firebase Cloud Messaging (FCM) in Android

Feb 1, 2024

Sami Abboud

Guide to integrate Firebase Cloud Messaging (FCM) in Android

Feb 1, 2024

Sami Abboud

Guide to integrate Firebase Cloud Messaging (FCM) in Android

Feb 1, 2024

Sami Abboud

Guide to integrate Firebase Cloud Messaging (FCM) in Android

Firebase Cloud Messaging (FCM), a Google service, enables developers to send push notifications to devices using Android, iOS, and web platforms. Leveraging Google Cloud Messaging (GCM) for its core messaging functionality, FCM enhances this with features like targeting specific groups of devices and confirming message delivery. It supports sending messages to offline devices and allows for the inclusion of custom data in messages.

In this step-by-step guide, we're going to show you how to easily integrate FCM in your Android application:

NOTE (Before running your app on device):

  1. Make sure your Android devices have at least Android 4.4 and the Google Play Store app installed.

  2. If you are using an emulator, set it to run Android 4.4 with Google APIs.

STEP 1 : Create Firebase Project and Register your App

Before you can add Firebase to your Android app, you need to create a Firebase project to connect to your Android app.

  1. In the  Firebase console, click  Add project.

  2. To add Firebase resources to an  existing  Google Cloud project, enter its project name or select it from the dropdown menu.

  3. To create a new project, enter the desired project name. You can also optionally edit the project ID displayed below the project name.

  4. Click  Create project  (or  Add Firebase, if you're using an existing Google Cloud project).

To use Firebase in your Android app, you need to register your app with your Firebase project. Registering your app is often called "adding" your app to your project.

  1. Go to the  Firebase console.

  2. In the center of the project overview page, click the  Android  icon (plat_android) or  Add app  to launch the setup workflow.

  3. Enter your app's package name in the  Android package name  field.

  4. Click  Register app.

NOTE : It is (Optional) to enter other app information: App nickname and Debug signing certificate SHA-1 in the steps above.

STEP 2 : Configure your App with Firebase (FCM)

Download and then add the Firebase Android configuration file (google-services.json) to your app:

  1. Click  Download google-services.json  to obtain your Firebase Android config file.

  2. Move your config file into the  module (app-level)  root directory of your app.

NOTE : To make the values in your google-services.json config file accessible to Firebase SDKs, you need the Google services Gradle plugin (google-services).

  1. In your root-level (project-level) Gradle file (<project>/build.gradle.kts or <project>/build.gradle), add the Google services plugin as a dependency:


  1. In your module (app-level) Gradle file (usually <project>/<app-module>/build.gradle.kts or <project>/<app-module>/build.gradle), add the Google services plugin:


  1. In your module (app-level) Gradle file (usually <project>/<app-module>/build.gradle.kts or <project>/<app-module>/build.gradle), add the dependencies for the Firebase products that you want to use in your app. We recommend using the Firebase Android BoM to control library versioning.


STEP 3 : Integrate Firebase Messaging (FCM) in your app's code.

1.  Edit your app manifest :

  1. Add the following to your app's manifest:

  • A service that extends FirebaseMessagingService. This is required if you want to do any message handling beyond receiving notifications on apps in the background. To receive notifications in foregrounded apps, to receive data payload, to send upstream messages, and so on, you must extend this service.


  1. Optionally you can add the below lines as well in your app's manifest:


2.  Request runtime notification permission on Android 13+

Android 13 introduces a new runtime permission for showing notifications. This affects all apps running on Android 13 or higher that use FCM notifications.

By default, the FCM SDK (version 23.0.6 or higher) includes the POST_NOTIFICATIONS permission defined in the manifest. However, your app will also need to request the runtime version of this permission via the constant,  android.permission.POST_NOTIFICATIONS Your app will not be allowed to show notifications until the user has granted this permission.

To request the new runtime permission:


3. Retrieve the current registration token

When you need to retrieve the current token, call FirebaseMessaging.getInstance().getToken() in your Activity/Fragment


4. Monitor token generation

The onNewToken callback fires whenever a new token is generated.


That's it! Your application is ready to recieve FCM Messages.

Read the full article on Gitlab: https://gitlab.com/aampe/android-push-notifications/-/blob/Phase1/README.md?ref_type=heads

0

Related

Shaping the future of marketing with Aampe through innovation, data.

Mar 6, 2025

Sami Abboud

Stop carrying half-eaten cake into your next sprint. Seriously. 🍰

Mar 6, 2025

Sami Abboud

Stop carrying half-eaten cake into your next sprint. Seriously. 🍰

Mar 6, 2025

Sami Abboud

Stop carrying half-eaten cake into your next sprint. Seriously. 🍰

Mar 6, 2025

Sami Abboud

Stop carrying half-eaten cake into your next sprint. Seriously. 🍰

Sep 28, 2022

Sami Abboud

A push notification recommender system for catalog products

Sep 28, 2022

Sami Abboud

A push notification recommender system for catalog products

Sep 28, 2022

Sami Abboud

A push notification recommender system for catalog products

Sep 28, 2022

Sami Abboud

A push notification recommender system for catalog products

Feb 6, 2024

Sami Abboud

Easily modifiable SQL code snippet for sampling from any random distribution given a discrete probability density function

Feb 6, 2024

Sami Abboud

Easily modifiable SQL code snippet for sampling from any random distribution given a discrete probability density function

Feb 6, 2024

Sami Abboud

Easily modifiable SQL code snippet for sampling from any random distribution given a discrete probability density function

Feb 6, 2024

Sami Abboud

Easily modifiable SQL code snippet for sampling from any random distribution given a discrete probability density function

Feb 1, 2024

Sami Abboud

In this step-by-step guide, we'll walk through how to easily integrate FCM in your iOS application:

Feb 1, 2024

Sami Abboud

In this step-by-step guide, we'll walk through how to easily integrate FCM in your iOS application:

Feb 1, 2024

Sami Abboud

In this step-by-step guide, we'll walk through how to easily integrate FCM in your iOS application:

Feb 1, 2024

Sami Abboud

In this step-by-step guide, we'll walk through how to easily integrate FCM in your iOS application:

Load More

Load More

Load More

Load More