Skip to main content

Custom Push Notification Styles

When a push notification is received, the system will display the notification with the push message.

  • FCM Push: For FCM push notifications, if the Push Method configured in the Console is set to Data Message, you can customize the notification style using the following methods.
  • RC Built-in Push: The notification style can be customized through the following methods. However, due to lower delivery rates, this approach is no longer recommended.
  • Other Third-Party Push Services: When the SDK receives push notifications from other third-party providers, the displayed notification is a system notification directly triggered by the underlying mobile OS, and thus does not support customization.

Custom Notification Styles

If you use FCM push and configure the Push Method as Data Message in the FCM backend, you can customize the notification style using the following methods.

Using PushEventListener

You can set up PushEventListener and override the preNotificationMessageArrived method to intercept notification events and customize the display.

tip
  • This feature is supported starting from SDK version 5.1.0.
  • Register the listener in the onCreate method of the Application.
  • Due to Android 12's notification trampoline restrictions, if your app's targetVersion ≥ 31, it is recommended to directly launch the Activity in the callback of RongPushClient.setPushEventListener. Avoid further message distribution via broadcasts or services before launching the Activity.

Sample Code

RongPushClient.setPushEventListener(
new PushEventListener() {
@Override
public boolean preNotificationMessageArrived(
Context context,
PushType pushType,
PushNotificationMessage notificationMessage) {
// This callback only takes effect for data messages. Return true to intercept, false to allow.
return false;
}

@Override
public void afterNotificationMessageArrived(
Context context,
PushType pushType,
PushNotificationMessage notificationMessage) {
// This callback only takes effect for data messages.
}

@Override
public boolean onNotificationMessageClicked(
Context context,
PushType pushType,
PushNotificationMessage notificationMessage) {
// Customize notification click behavior here. Return true to intercept, false to allow.
return false;
}

@Override
public void onThirdPartyPushState(
PushType pushType, String action, long resultCode) {}
});

Using PushMessageReceiver

You can also customize FCM notification styles via the onNotificationMessageArrived method of PushMessageReceiver. This method has lower priority than PushEventListener.

tip

Due to Android 12's notification trampoline restrictions, if your app's targetVersion ≥ 31, it is recommended to directly launch the Activity in the callback of PushMessageReceiver. Avoid further message distribution via broadcasts or services before launching the Activity.

  1. Create a custom YourCustomPushMessageReceiver that extends PushMessageReceiver. The onNotificationMessageArrived (notification arrival event) will receive the push content.

Sample Code

public class YourCustomMessageReceiver extends PushMessageReceiver {

@Override
public boolean onNotificationMessageClicked(
Context context, PushType pushType, PushNotificationMessage message) {
if (pushType.equals(PushType.GOOGLE_FCM)){

// TODO
}
// Return true to intercept, false to allow.
return true;
}
}
  1. Register your custom push broadcast receiver component in the AndroidManifest.xml of the main project. Replace any existing PushMessageReceiver registration in AndroidManifest.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>