DEV Community

loizenai
loizenai

Posted on

Kotlin Firebase Cloud Messaging – How to Receive Messages | Android

https://grokonez.com/android/kotlin-firebase-cloud-messaging-receive-messages-android

Kotlin Firebase Cloud Messaging – How to Receive Messages | Android

Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that help us deliver messages reliably at no cost. In this tutorial, we're gonna look at way to receive Messages in an Android App using FCM.

More Practice: Kotlin Firebase Cloud Messaging – How to Subscribe TOPIC & Receive Messages | Android

I. Firebase Cloud Messaging

1. Usage

With FCM, we can:

  • notify a client that new data is available to sync.
  • send notification messages to drive user re-engagement and retention.
  • create instant messaging with a payload of up to 4KB to a client app.

    2. How to receive Messages

    2.1 Add Firebase to Android Project

  • Create new Android App including Kotlin support.
  • From menu bar, Tool -> Firebase:
    kotlin-firebase-cloud-messaging-setup-tool

  • Assistant window will be shown. Choose Cloud Messaging, then click on Setup Firebase Cloud Messaging:
    kotlin-firebase-cloud-messaging-setup-tool-2

  • At the step 1, click on Connect to Firebase:
    kotlin-firebase-cloud-messaging-setup-tool-3

  • In new Window, choose Create new Project and fill in the name of Firebase Project:
    kotlin-firebase-cloud-messaging-setup-tool-4

  • Click on Connect to Firebase, the Browser will show new Firebase Project that has just been created:
    kotlin-firebase-cloud-messaging-setup-tool-console

  • Come back to Android Studio, at the step 2, click on Add FCM to your app:
    kotlin-firebase-cloud-messaging-setup-tool-5

  • You will see a new window that shows the code will be add to build.gradle files. Click on Accept Changes:
    kotlin-firebase-cloud-messaging-setup-tool-6

  • Now view your Project under Project type, you can see google-services.json file:
    kotlin-firebase-cloud-messaging-setup-tool-7

    2.2 Check dependencies

    Open Gradle file to check what happens, we can see that some code has been added:

  • build.gradle (project-level):

    
    buildscript {
    // ...
    dependencies {
        // ...
        classpath 'com.google.gms:google-services:3.1.0'
    }
    }
    
  • build.gradle (App-level):

More at:

https://grokonez.com/android/kotlin-firebase-cloud-messaging-receive-messages-android

Kotlin Firebase Cloud Messaging – How to Receive Messages | Android

Top comments (0)