---
url: https://talkjs.com/docs/UI_Components/Android/Push_Notifications/
title: "Push notifications | Android | TalkJS Docs"
---

For AI agents: Find a documentation index at https://talkjs.com/llms.txt (full content at https://talkjs.com/llms-full.txt). Get a markdown version of any page by appending .md to its URL path.

# Push notifications

Show TalkJS push notifications in your app.

## object TalkJSNotifications

Entry point for displaying push notifications and reacting to them.

### Method Overview

<table class="my-0"><tbody><tr class="flex flex-col flex-no-wrap sm:table-row"><td><a href="https://talkjs.com/docs/UI_Components/Android/Push_Notifications/#TalkJSNotifications__handleRemoteMessage" class="no-underline font-mono text-blue-500 hover:text-blue-600 font-medium">handleRemoteMessage</a></td><td><p>This function handles TalkJS originated push notifications on Android.</p></td></tr><tr class="flex flex-col flex-no-wrap sm:table-row"><td><a href="https://talkjs.com/docs/UI_Components/Android/Push_Notifications/#TalkJSNotifications__registerPushNotificationHandlers" class="no-underline font-mono text-blue-500 hover:text-blue-600 font-medium">registerPushNotificationHandlers</a></td><td><p>This function sets up the push notification handlers. It is meant to be called before this app starts receiving push notifications.</p></td></tr><tr class="flex flex-col flex-no-wrap sm:table-row"><td><a href="https://talkjs.com/docs/UI_Components/Android/Push_Notifications/#TalkJSNotifications__requestNotificationPermissions" class="no-underline font-mono text-blue-500 hover:text-blue-600 font-medium">requestNotificationPermissions</a></td><td><p>Asks the user for the permission to show notifications.</p><p>On Android 13 (API 33) and above, this shows the system permission prompt unless the permission has already been granted. On older versions, this does nothing.</p></td></tr><tr class="flex flex-col flex-no-wrap sm:table-row"><td><a href="https://talkjs.com/docs/UI_Components/Android/Push_Notifications/#TalkJSNotifications__updateInstallationId" class="no-underline font-mono text-blue-500 hover:text-blue-600 font-medium">updateInstallationId</a></td><td><p>This function handles refreshed Firebase installation IDs on Android.</p></td></tr></tbody></table>

### Properties

**EXTRA\_BODY**: String

Intent extra key (`String?`) for the body text of the notification, if it has one.

**EXTRA\_CONVERSATION\_ID**: String

Intent extra key (`String`) for the ID of the conversation the notification belongs to, or an empty string if the notification carries no message data.

**EXTRA\_IS\_FOREGROUND\_EVENT**: String

Intent extra key (`Boolean`) for whether the app was in the foreground when the notification was pressed.

**EXTRA\_MESSAGE\_ID**: String

Intent extra key (`String`) for the ID of the message. Only present if the notification carries message data.

**EXTRA\_SENDER\_ID**: String

Intent extra key (`String`) for the ID of the user who sent the message. Only present if the notification carries message data.

**EXTRA\_TIMESTAMP**: String

Intent extra key (`Long`) for when the message was sent, in milliseconds since the Unix epoch. Only present if the notification carries message data.

**EXTRA\_TITLE**: String

Intent extra key (`String?`) for the title of the notification, if it has one.

### handleRemoteMessage

fun _talkJSNotifications_.handleRemoteMessage(context, remoteMessage): Boolean

This function handles TalkJS originated push notifications on Android.

It is expected to be called inside a custom `FirebaseMessagingService.onMessageReceived` handler. Use it when [PushNotificationSettings.registerBackgroundHandler](https://talkjs.com/docs/UI_Components/Android/Push_Notifications/#PushNotificationSettings__registerBackgroundHandler) is `false`.

#### Parameters

**context**: Context

The context of the calling `FirebaseMessagingService`.

**remoteMessage**: RemoteMessage

The remote FCM message payload.

#### Returns

Boolean

`true` if the push notification was TalkJS originated and handled by this function. A `false` return value means that the push notification was not TalkJS originated and not handled by this function.

### registerPushNotificationHandlers

fun _talkJSNotifications_.registerPushNotificationHandlers(context, userProvider, onNewInstallationId, onNotificationPressed, activityToOpen, settings)

This function sets up the push notification handlers. It is meant to be called before this app starts receiving push notifications.

#### Parameters

**context**: Context

The context used to register the notification channel and handler.

**userProvider _(optional)_**: (suspend () -> [UserRef](https://talkjs.com/docs/Data_APIs/Kotlin/Users/#UserRef))?

Suspend function that returns the UserRef used to register the Firebase installation ID. If set, the library calls it every time the installation ID changes, registers the new installation ID and removes the old one.

**onNewInstallationId _(optional)_**: ((oldInstallationId: String?, newInstallationId: String) -> Unit)?

Called when the Firebase installation ID is first obtained or changes. `oldInstallationId` is `null` the first time.

**onNotificationPressed _(optional)_**: ((event: [NotificationPressedEvent](https://talkjs.com/docs/UI_Components/Android/Push_Notifications/#NotificationPressedEvent)) -> Unit)?

Called when the user taps a TalkJS notification.

The callback is kept for as long as the process is running, so don't capture an `Activity` or any other short-lived object in it.

**activityToOpen _(optional)_**: Class<out Activity\>?

The activity to start when the user taps a TalkJS notification.

The activity should override `onNewIntent` to handle a tap while it is already open. The intent has the extra fields keyed by the `EXTRA_` constants of [TalkJSNotifications](https://talkjs.com/docs/UI_Components/Android/Push_Notifications/#TalkJSNotifications).

**settings**: [PushNotificationSettings](https://talkjs.com/docs/UI_Components/Android/Push_Notifications/#PushNotificationSettings)

The [PushNotificationSettings](https://talkjs.com/docs/UI_Components/Android/Push_Notifications/#PushNotificationSettings) that describe the notification channel and how notifications are displayed.

#### Returns

Unit

### requestNotificationPermissions

fun _talkJSNotifications_.requestNotificationPermissions(activity, requestCode)

Asks the user for the permission to show notifications.

On Android 13 (API 33) and above, this shows the system permission prompt unless the permission has already been granted. On older versions, this does nothing.

#### Parameters

**activity**: Activity

The activity the system permission prompt is shown from.

**requestCode**: Int

The request code to identify this request in `Activity.onRequestPermissionsResult`.

#### Returns

Unit

### updateInstallationId

fun _talkJSNotifications_.updateInstallationId(context, newInstallationId)

This function handles refreshed Firebase installation IDs on Android.

It is expected to be called inside a custom `FirebaseMessagingService.onRegistered` handler. Use it when [PushNotificationSettings.registerBackgroundHandler](https://talkjs.com/docs/UI_Components/Android/Push_Notifications/#PushNotificationSettings__registerBackgroundHandler) is `false`.

#### Parameters

**context**: Context

The context of the calling `FirebaseMessagingService`.

**newInstallationId**: String

The new Firebase installation ID.

#### Returns

Unit

## data class PushNotificationSettings

Describes the notification channel that push notifications are posted to, and how they are displayed.

Android doesn't let you change a channel's importance or other behavior after the channel has been created. To change them, use a new [channelId](https://talkjs.com/docs/UI_Components/Android/Push_Notifications/#PushNotificationSettings).

### Properties

**bypassDnd _(optional)_**: Boolean?

Whether notifications posted to this channel can bypass Do Not Disturb.

**channelDescription _(optional)_**: String?

The description of the notification channel, as shown to the user in the system settings.

**channelId**: String

The ID of the notification channel.

**channelName**: String

The name of the notification channel, as shown to the user in the system settings.

**importance**: Int

The importance of the notification channel, as one of the `NotificationManager.IMPORTANCE_*` constants.

Defaults to `NotificationManager.IMPORTANCE_HIGH`.

**lightColor _(optional)_**: Int?

The color of the notification light.

**lights _(optional)_**: Boolean?

Whether notifications posted to this channel flash the device's notification light.

**registerBackgroundHandler**: Boolean

Whether the library receives push notifications on its own, using its built-in Firebase messaging service.

Set this to `false` if your app has its own `FirebaseMessagingService`, and call [TalkJSNotifications.handleRemoteMessage](https://talkjs.com/docs/UI_Components/Android/Push_Notifications/#TalkJSNotifications__handleRemoteMessage) from its `onMessageReceived` instead.

Defaults to `true`.

**showBadge _(optional)_**: Boolean?

Whether notifications posted to this channel can show a badge on the app's launcher icon.

**showInForeground**: Boolean

Whether to display a push notification while the app is in the foreground.

Defaults to `false`.

**smallIcon _(optional)_**: Int?

The drawable resource ID of the small icon shown in the notification.

Defaults to the app's icon.

**soundUri _(optional)_**: Uri?

The sound played by notifications posted to this channel.

Defaults to the system's default notification sound.

**vibration _(optional)_**: Boolean?

Whether notifications posted to this channel vibrate the device.

**vibrationPattern _(optional)_**: LongArray?

The vibration pattern of notifications posted to this channel.

**visibility**: Int

Whether the content of notifications is visible on the lock screen, as one of the `NotificationCompat.VISIBILITY_*` constants.

Defaults to `NotificationCompat.VISIBILITY_PRIVATE`.

## data class NotificationPressedEvent

An event object dispatched by the `onNotificationPressed` callback of [TalkJSNotifications.registerPushNotificationHandlers](https://talkjs.com/docs/UI_Components/Android/Push_Notifications/#TalkJSNotifications__registerPushNotificationHandlers).

### Properties

**body _(optional)_**: String?

The body text of the notification, if it has one.

**data _(optional)_**: [NotificationPressedData](https://talkjs.com/docs/UI_Components/Android/Push_Notifications/#NotificationPressedData)?

The message the notification is showing, or `null` if the notification carries no message data.

**id**: String

The ID of the conversation the notification belongs to, or an empty string if [data](https://talkjs.com/docs/UI_Components/Android/Push_Notifications/#NotificationPressedEvent) is `null`.

**isForegroundEvent**: Boolean

Whether the app was in the foreground when the notification was pressed.

**title _(optional)_**: String?

The title of the notification, if it has one.

## data class NotificationPressedData

Describes the message that a pressed notification is showing.

### Properties

**conversationId**: String

The ID of the conversation the message was sent in.

**messageId**: String

The ID of the message.

**senderId**: String

The ID of the user who sent the message.

**timestamp**: Long

When the message was sent, in milliseconds since the Unix epoch.
