Push notifications
Show TalkJS push notifications in your app.
Entry point for displaying push notifications and reacting to them.
| handleRemoteMessage | This function handles TalkJS originated push notifications on Android. |
| registerPushNotificationÂHandlers | This function sets up the push notification handlers. It is meant to be called before this app starts receiving push notifications. |
| requestNotificationPermissions | 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. |
| updateInstallationId | This function handles refreshed Firebase installation IDs on Android. |
Intent extra key (String?) for the body text of the notification, if it has one.
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.
Intent extra key (Boolean) for whether the app was in the foreground when the notification was pressed.
Intent extra key (String) for the ID of the message. Only present if the notification carries message data.
Intent extra key (String) for the ID of the user who sent the message. Only present if the notification carries message data.
Intent extra key (Long) for when the message was sent, in milliseconds since the Unix epoch. Only present if the notification carries message data.
Intent extra key (String?) for the title of the notification, if it has one.
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 is false.
Parameters
The context of the calling FirebaseMessagingService.
The remote FCM message payload.
Returns
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.
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
The context used to register the notification channel and handler.
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.
Called when the Firebase installation ID is first obtained or changes. oldInstallationId is null the first time.
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.
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.
The PushNotificationSettings that describe the notification channel and how notifications are displayed.
Returns
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
The activity the system permission prompt is shown from.
The request code to identify this request in Activity.onRequestPermissionsResult.
Returns
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 is false.
Parameters
The context of the calling FirebaseMessagingService.
The new Firebase installation ID.
Returns
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.
Whether notifications posted to this channel can bypass Do Not Disturb.
The description of the notification channel, as shown to the user in the system settings.
The ID of the notification channel.
The name of the notification channel, as shown to the user in the system settings.
The importance of the notification channel, as one of the NotificationManager.IMPORTANCE_* constants.
Defaults to NotificationManager.IMPORTANCE_HIGH.
The color of the notification light.
Whether notifications posted to this channel flash the device's notification light.
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 from its onMessageReceived instead.
Defaults to true.
Whether notifications posted to this channel can show a badge on the app's launcher icon.
Whether to display a push notification while the app is in the foreground.
Defaults to false.
The drawable resource ID of the small icon shown in the notification.
Defaults to the app's icon.
The sound played by notifications posted to this channel.
Defaults to the system's default notification sound.
Whether notifications posted to this channel vibrate the device.
The vibration pattern of notifications posted to this channel.
Whether the content of notifications is visible on the lock screen, as one of the NotificationCompat.VISIBILITY_* constants.
Defaults to NotificationCompat.VISIBILITY_PRIVATE.
An event object dispatched by the onNotificationPressed callback of TalkJSNotifications.registerPushNotificationHandlers.
The body text of the notification, if it has one.
The message the notification is showing, or null if the notification carries no message data.
The ID of the conversation the notification belongs to, or an empty string if data is null.
Whether the app was in the foreground when the notification was pressed.
The title of the notification, if it has one.
Describes the message that a pressed notification is showing.
The ID of the conversation the message was sent in.
The ID of the message.
The ID of the user who sent the message.
When the message was sent, in milliseconds since the Unix epoch.