Skip to main content

Handle push notification clicks

This guide explains how the SDK handles push notification tap events by default and how your app can customize that behavior.

tip

This guide only covers remote push notification click events. For local notification click handling, see the related documentation.

Implement the default navigation behavior

The SDK handles remote push notification tap events by default. When a user taps a notification, the SDK sends an implicit Intent. Configure an Intent filter in your app's AndroidManifest.xml to receive the Intent and complete the default navigation.

  • Notification from a single sender: When the user taps one or more notifications from the same sender, the SDK navigates to the channel Activity.
  • Collapsed notifications from multiple senders: When multiple senders send notifications, the notifications are collapsed. Tapping a collapsed notification navigates to the channel list Activity.
  • We recommend navigating to the channel list page by default. Call the connect method before opening the channel list to ensure the latest messages are visible.

Navigate to the channel page

When the user taps notifications from a single sender, the SDK sends an Intent to navigate to the channel Activity.

Add the following intent-filter to the Activity that opens a single conversation in your app. The Android Chat SDK does not ship a built-in conversation UI Activity, so replace com.example.app.chat.ChannelActivity with your own class.

xml
<activity
android:name="com.example.app.chat.ChannelActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="${applicationId}"
android:pathPrefix="/conversation"
android:scheme="rong" />
</intent-filter>
</activity>

When the user taps collapsed notifications from multiple senders, the SDK sends an Intent to navigate to the channel list Activity.

Add the following intent-filter to the Activity that opens your conversation list. The Android Chat SDK does not ship a built-in conversation list UI Activity, so replace com.example.app.chat.ChannelListActivity with your own class.

xml
<activity
android:name="com.example.app.chat.ChannelListActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="${applicationId}"
android:pathPrefix="/conversationlist"
android:scheme="rong" />
</intent-filter>
</activity>

Customize notification click behavior

If the default navigation behavior does not meet your needs, extend PushMessageReceiver and override onNotificationMessageClicked.

Use PushMessageReceiver

You can customize click behavior through PushMessageReceiver's onNotificationMessageClicked method.

tip
  • Huawei Push click events cannot be customized through PushMessageReceiver.
  • Due to Android 12 notification trampoline restrictions, if your app targets API level 31 or higher, start the Activity directly in the PushMessageReceiver callback. Do not route through a broadcast or service before launching the Activity.
  1. Create a CustomPushMessageReceiver extending PushMessageReceiver.

    kotlin
    class CustomPushMessageReceiver : PushMessageReceiver() {
    // ...
    }
  2. Register the custom receiver in your app's AndroidManifest.xml. Replace any existing PushMessageReceiver registration.

    xml
      <receiver
    android:name="xxx.CustomPushMessageReceiver"
    android:exported="true">
    <intent-filter>
    <action android:name="io.rong.push.intent.MESSAGE_ARRIVED" />
    <action android:name="io.rong.push.intent.MESSAGE_CLICKED" />
    <action android:name="io.rong.push.intent.THIRD_PARTY_PUSH_STATE" />
    </intent-filter>
    </receiver>
  3. Override onNotificationMessageClicked in your CustomPushMessageReceiver class. Intercept the event and implement your navigation logic.

    Parameters

    ParameterTypeRequiredDescription
    contextContextYesThe context object.
    pushTypePushTypeYesThe push provider type.
    notificationMessagePushNotificationMessageYesThe push notification message.
    kotlin
    class CustomPushMessageReceiver : PushMessageReceiver() {
    override fun onNotificationMessageClicked(context: Context, pushType: PushType, notificationMessage: PushNotificationMessage): Boolean {
    return when (pushType) {
    PushType.HUAWEI -> true
    PushType.GOOGLE_FCM -> true
    else -> false
    }
    }
    }