Menu Close

5 steps to easily integrate FCM in your android app

Firebase Cloud Messaging (FCM) is a cross platform messaging solution by Google. Since Google Cloud Messaging (GCM) was deprecated on April 10, 2018 (GCM servers will be removed by May 29, 2019), a lot of android developers are trying to switch over to FCM. Today we look at the steps involved in integrating FCM in your android app:

1) Create a sample android app

Open your Android Studio and create a new project. Name it SampleFCM. Change the company domain to

2) Register your app with firebase

  • Login to Firebase.
  • Click on Add Project, give it a name and click Create Project.
  • In the getting started window, click on the android icon.
  • Enter your app’s package name (from build.gradle). For our sample app the package name is com.apnstester.samplefcm.
  • Click Register App.
  • Download the google-services.json file. Put that file in your project’s app folder (in android studio).

3) Add dependencies to your build.gradle

  • Open your app level build.gradle file (SampleFCM/app/build.gradle).
  • Add the firebase dependency and google services plugin.

    // other dependencies

    implementation ''
    implementation ''

apply plugin: ''
  • Open the root build.gradle ( SampleFCM/build.gradle ) and add the below line under dependencies.
dependencies {
        classpath ''

        classpath '' // ADD THIS LINE
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
fcm google-services classpath

3) Creating the Firebase Service

  • Create a new java class and name it MyFirebaseService.
  • Make the class extend FirebaseMessagingService.
  • Override the onMessageReceived method and fill in the code like below:
public class MyFirebaseService extends FirebaseMessagingService {
public void onMessageReceived(RemoteMessage remoteMessage) {

Intent intent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "default")

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

4) Add the service to your AndroidManifest.xml file

All services that your use in your android code need to be explicitly mentioned in the manifest file. Add the below code to your AndroidManifest.xml file under the <application> tag.

<action android:name="" />

5) Testing your code

  • Add the below code to the onCreate method of your MainActivity to get the device token:
  • Connect your android device and run the application on it (you cannot test FCM on a simulator).
  • In logcat window, search for fcmtoken. Copy and save the token. We will need it later.
  • In your firebase console, go to Project Settings -> Cloud Messaging and copy the server key.
  • Go to and paste your server key and fcm token there.
  • In message, enter “Testing FCM with” .
  • Make sure your app is in background so that your can see the notification show up on your phone. ( app in background means close the application or press the home button on your android device).
  • Click Test.
  • Check your android device and verify that you have received a notification.

Leave a Reply

Your email address will not be published. Required fields are marked *