Skip to main content

Customize push notification style

When the app receives a push notification, the system displays a notification. You can customize the notification appearance depending on the push provider:

  • FCM push: If the push method is set to data message in the Console, you can customize the notification style using the method below.
  • Other push providers: Notifications from other vendor push providers are system-level notifications displayed directly by the OS. Customization is not supported.

Customize notification style

If you use FCM push and the push method is set to data message in the Console, customize the notification style through PushMessageReceiver.onNotificationMessageArrived().

Use PushMessageReceiver

Use PushMessageReceiver.onNotificationMessageArrived() to intercept the incoming FCM data message and apply your custom notification display logic.

tip

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 custom YourCustomPushMessageReceiver that extends PushMessageReceiver. Use onNotificationMessageArrived to receive push content.

    Example

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

    xml
    <receiver
    android:name="xxx.YourCustomPushMessageReceiver"
    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>