Stay organized with collectionsSave and categorize content based on your preferences.
To get started withFCM, build out the simplest use case: sending a
test notification message from theNotifications composerto a development device
when the app is in the background on the device.
This page lists all the steps to achieve this, from setup to verification
— it may cover steps you already completed if you
haveset up an Android client appforFCM.
Set up the SDK
This section covers tasks you may have completed if you have already enabled
other Firebase features for your app.
If you don't already have an Android project and just want to try out a Firebase
product, you can download one of ourquickstart samples.
Create a Firebase project
Before you can add Firebase to your Android app, you need to create a Firebase
project to connect to your Android app. VisitUnderstand Firebase Projectsto learn more about
Firebase projects.
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.
In the center of the project overview page, click theAndroidicon
(plat_android)
orAdd appto launch the setup workflow.
Enter your app's package name in theAndroid package namefield.
What's a package name, and where do you find it?
Apackage
nameuniquely identifies your app on the device and in the Google Play Store.
Apackage nameis often referred to as anapplication ID.
Find your app's package name in your module (app-level) Gradle file,
usuallyapp/build.gradle(example package name:com.yourcompany.yourproject).
Be aware that the package name value is case-sensitive, and it cannot be
changed for this Firebase Android app after it's registered with your
Firebase project.
(Optional)Enter other app information:App nicknameandDebug signing certificate SHA-1.
How are theApp nicknameand theDebug signing certificate SHA-1used within Firebase?
App nickname: An internal, convenience identifier that is only
visible to you in theFirebaseconsole
Download and then add your app's Firebase config file
(google-services.json) to your codebase:
ClickDownload google-services.jsonto obtain your app's Firebase
config file.
Move your config file into themodule (app-level)root directory of
your app.
What do you need to know about this config file?
The Firebase config file contains unique, but non-secret identifiers for
your project and app. To learn more about this config file, visitUnderstand Firebase
Projects.
Make sure the config file name is not appended with additional characters,
like(2).
To make the values in yourgoogle-services.jsonconfig file accessible
to Firebase SDKs, you need theGoogle services Gradle plugin(google-services).
In yourroot-level (project-level)Gradle file
(<project>/build.gradle.ktsor<project>/build.gradle), add the
Google services plugin as a dependency:
Kotlin
plugins{id("com.android.application")version"7.3.0"applyfalse// ...// Add the dependency for the Google services Gradle pluginid("com.google.gms.google-services")version"4.4.3"applyfalse}
Groovy
plugins{id'com.android.application'version'7.3.0'applyfalse// ...// Add the dependency for the Google services Gradle pluginid'com.google.gms.google-services'version'4.4.3'applyfalse}
In yourmodule (app-level)Gradle file
(usually<project>/<app-module>/build.gradle.ktsor<project>/<app-module>/build.gradle),
add the Google services plugin:
Kotlin
plugins{id("com.android.application")// Add the Google services Gradle pluginid("com.google.gms.google-services")// ...}
Groovy
plugins{id'com.android.application'// Add the Google services Gradle pluginid'com.google.gms.google-services'// ...}
Add Firebase SDKs to your app
In yourmodule (app-level) Gradle file(usually<project>/<app-module>/build.gradle.ktsor<project>/<app-module>/build.gradle),
add the dependency for theFirebase Cloud Messaginglibrary for Android. We recommend using theFirebase Android BoMto control library versioning.
For an optimal experience withFirebase Cloud Messaging, we recommendenablingGoogle Analyticsin your Firebase project and adding the Firebase SDK for Google Analytics to your app.
dependencies{// Import theBoMfor the Firebase platformimplementation(platform("com.google.firebase:firebase-bom:34.2.0"))// Add the dependencies for theFirebase Cloud MessagingandAnalyticslibraries// When using theBoM, you don't specify versions in Firebase library dependenciesimplementation("com.google.firebase:firebase-messaging")implementation("com.google.firebase:firebase-analytics")}
By using theFirebase Android BoM,
your app will always use compatible versions of Firebase Android libraries.
(Alternative)
Add Firebase library dependencies without using theBoM
If you choose not to use theFirebase BoM, you must specify each Firebase library version
in its dependency line.
Note that if you usemultipleFirebase libraries in your app, we strongly
recommend using theBoMto manage library versions, which ensures that all versions are
compatible.
dependencies{// Add the dependencies for theFirebase Cloud MessagingandAnalyticslibraries// When NOT using theBoM, you must specify versions in Firebase library dependenciesimplementation("com.google.firebase:firebase-messaging:25.0.0")implementation("com.google.firebase:firebase-analytics:23.0.0")}
Sync your Android project with Gradle files.
Are you getting a build failure about invoke-custom support and enabling
desugaring? Here's how to fix it.
Gradle builds that use Android Gradle plugin (AGP) v4.2 or earlier need to
enable Java 8 support. Otherwise, these Android projects get a build
failure when adding a Firebase SDK.
To fix this build failure, you can follow one of two options:
Add the listedcompileOptionsfrom the error message to yourapp-levelbuild.gradle.ktsorbuild.gradlefile.
Increase theminSdkfor your Android project to 26 or above.
To send a message to a specific device, you need to know that device's
registration token. Because you'll need to enter the token in a field in the
Notifications console to complete this tutorial, make sure to copy the token
or securely store it after you retrieve it.
On initial startup of your app, theFCMSDK generates a registration
token for the client app instance. If you want to target single devices or
create device groups, you'll need to access this token by extendingFirebaseMessagingServiceand overridingonNewToken. Because the
token could be rotated after initial
startup, you are strongly recommended to retrieve the latest updated registration
token.
FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener{task->if(!task.isSuccessful){Log.w(TAG,"Fetching FCM registration token failed",task.exception)return@OnCompleteListener}// Get new FCM registration tokenvaltoken=task.result// Log and toastvalmsg=getString(R.string.msg_token_fmt,token)Log.d(TAG,msg)Toast.makeText(baseContext,msg,Toast.LENGTH_SHORT).show()})
Java
FirebaseMessaging.getInstance().getToken().addOnCompleteListener(newOnCompleteListener<String>(){@OverridepublicvoidonComplete(@NonNullTask<String>task){if(!task.isSuccessful()){Log.w(TAG,"Fetching FCM registration token failed",task.getException());return;}// Get new FCM registration tokenStringtoken=task.getResult();// Log and toastStringmsg=getString(R.string.msg_token_fmt,token);Log.d(TAG,msg);Toast.makeText(MainActivity.this,msg,Toast.LENGTH_SHORT).show();}});
Monitor token generation
TheonNewTokencallback fires whenever a new token is generated.
Kotlin
/*** Called if the FCM registration token is updated. This may occur if the security of* the previous token had been compromised. Note that this is called when the* FCM registration token is initially generated so this is where you would retrieve the token.*/overridefunonNewToken(token:String){Log.d(TAG,"Refreshed token:$token")// If you want to send messages to this application instance or// manage this apps subscriptions on the server side, send the// FCM registration token to your app server.sendRegistrationToServer(token)}
/*** There are two scenarios when onNewToken is called:* 1) When a new token is generated on initial app startup* 2) Whenever an existing token is changed* Under #2, there are three scenarios when the existing token is changed:* A) App is restored to a new device* B) User uninstalls/reinstalls the app* C) User clears app data*/@OverridepublicvoidonNewToken(@NonNullStringtoken){Log.d(TAG,"Refreshed token: "+token);// If you want to send messages to this application instance or// manage this apps subscriptions on the server side, send the// FCM registration token to your app server.sendRegistrationToServer(token);}
Otherwise, on theCampaignstab, selectNew campaignand thenNotifications.
Enter the message text. All other fields are optional.
SelectSend test messagefrom the right pane.
In the field labeledAdd an FCM registration token, enter the registration
token you obtained in a previous section of this guide.
SelectTest.
After you selectTest, the targeted client device (with the app in
the background) should receive the notification.
For insight into message delivery to your app, see
theFCMreporting dashboard, which records the
number of messages sent and opened on Apple and Android devices, along with
data for "impressions" (notifications seen by users) for Android apps.
Next steps
Send messages to foregrounded apps
Once you have successfully sent notification messages while your app is in
the background, seeReceive Messages in an Android Appto get started sending to foregrounded apps.
Go beyond notification messages
To go beyond notification messages and add other, more advanced behavior to your
app, see:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,[]]