Rongyun--IMKit comes with message push

Versions after 2.6.0 must customize a broadcast receiver that inherits PushMessageReceiver, otherwise it may cause problems such as clicking the background notification and not responding, or not receiving push notifications.

1. Customize a BroadcastReceiver class

Inherit the PushMessageReceiver class and implement the onNotificationMessageArrived and onNotificationMessageClicked methods.

public class DemoNotificationReceiver extends PushMessageReceiver {
   /**
     * 用来接收服务器发来的通知栏消息(消息到达客户端时触发)
     * 默认return false,通知消息会以融云 SDK 的默认形式展现
     * 如果需要自定义通知栏的展示,在这里实现⾃己的通知栏展现代码,只要return true即可
     */
    @Override
    public boolean onNotificationMessageArrived(Context context, PushNotificationMessage message) {

        return false;
    }
     /**
     * ⽤户点击通知栏消息时触发 (注意:如果⾃定义了通知栏的展现,则不会触发)
     * 默认 return false
     * 如果需要自定义点击通知时的跳转,return true即可
     */
    @Override
    public boolean onNotificationMessageClicked(Context context, PushNotificationMessage message) {
        return false;
    }
}

2. Register the DemoNotificationReceiver in the AndroidManifest.xml of the application

<receiver
    android:exported="true"
    android:name="您自定义的 broadcastReceiver 类名">
    <intent-filter>
        <action android:name="io.rong.push.intent.MESSAGE_ARRIVED" />
        <action android:name="io.rong.push.intent.MI_MESSAGE_ARRIVED" />
        <action android:name="io.rong.push.intent.MESSAGE_CLICKED" />
        <action android:name="io.rong.push.intent.MI_MESSAGE_CLICKED" />
    </intent-filter>
</receiver>

3. Intercept the click of the push message

The following action event is triggered by default when the push message is clicked:

Intent intent = new Intent();
intent.setFlags(intent.FLAG_ACTIVITY_NEW_TASK);

Uri.Builder uriBuilder = Uri.parse("rong://" + this.getPackageName()).buildUpon();
uriBuilder.appendPath("push_message")
        .appendQueryParameter("targetId", targetId)
        .appendQueryParameter("pushData", pushData)
        .appendQueryParameter("pushId", pushId)
        .appendQueryParameter("extra", extra);

startActivity(intent);

At this time, we can configure A activity in your AndroidManifest.xml to intercept this action, then it will jump to activity A when clicked.

<activity
android:name="A"
android:launchMode="singleTask"
android:screenOrientation="portrait">

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />

    <data
        android:host="你的包名"
        android:pathPrefix="/push_message"
        android:scheme="rong" />
</intent-filter>
</activity>

For details, please click: Android Push Service Development Guide

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325357488&siteId=291194637