> For the complete documentation index, see [llms.txt](https://doc.appflow.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.appflow.ai/docs/sdk-set-up-instructions/android-sdk/push-notifications.md).

# Push notifications

The part of SDK needed to connect with your users through push-notifications

***

**Add configuration file**\
Create a project via the Firebase console, and download the google-services.json and move it into the app's modules (app level) directory

**Apply gradle plugin**\
a、If your project doesn't have dependencyResolutionManagement in your settings.gradle, add the following to your top-level build.gradle at the end of repositories：

**top-level build.gradle**

```kotlin
allprojects {
  repositories {
    ...
    // Check that you have the following line (if not, add it):
    google()  // Google's Maven repository
  }
}
```

Otherwise add the following to your settings.gradle in repositories of dependencyResolutionManagement section：

**settings.gradle**

```kotlin
dependencyResolutionManagement {
    repositories {
        ...
        // Check that you have the following line (if not, add it):
    		google()  // Google's Maven repository
    }
}
```

b、 add the following to your top-level build.gradle

**top-level build.gradle**

```kotlin
buildscript {
  repositories {
    // Check that you have the following line (if not, add it):
    google()  // Google's Maven repository
  }

  dependencies {
    // Add the following line:
    classpath 'com.google.gms:google-services:4.3.10'  // Google Services plugin
  }
}
```

c、In your module (app-level) Gradle file (usually app/build.gradle), apply the Google Services Gradle plugin:

**app-level build.gradle**

```kotlin
apply plugin: 'com.android.application'
// Add the following line:
apply plugin: 'com.google.gms.google-services'  // Google Services plugin

android {
  // ...
  // add the firebase dependency
  implementation platform('com.google.firebase:firebase-bom:29.0.3')
  implementation 'com.google.firebase:firebase-analytics'
  implementation 'com.google.firebase:firebase-messaging'  
}
```

notification message\
To get push messages, you have to call method:

```kotlin
Appflow.setListener(listener: FirebaseMsgListener)
```

**Example**

```kotlin
Appflow.setFirebaseMsgListener(object : Appflow.FirebaseMsgListener {
    override fun onNewToken(token: String) {
				//When the Firebase token is updated, it will be called back through this method
    }

    override fun onMessageReceived(remoteMessage: RemoteMessage) {
      	//When the App is in the background, when a push notification message is received, 
        //a notification will pop up directly in the system bar.
      	//When the App is in the foreground, a push notification is received, 
        //and the message is called back through this method.
        remoteMessage.notification?.let {
            Log.d(TAG,"Title:${it.title} Body: ${it.body}")
        }
    }
})
```

**API Reference**

| FirebaseMsgListener                             |                                                                                                                   |
| ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| onNewToken(token: String)                       | When the Firebase token is updated, it will be called back through this method                                    |
| onMessageReceived(remoteMessage: RemoteMessage) | Push notification message callback (when the App is in the foreground, the push notification will be called back) |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://doc.appflow.ai/docs/sdk-set-up-instructions/android-sdk/push-notifications.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
