融云--IMKit 自带消息推送

2.6.0 之后的版本必须自定义一个继承 PushMessageReceiver 的广播接收器,否则可能会导致点击后台通知没有反应,或者收不到推送通知等问题。

1、自定义一个 BroadcastReceiver 类

继承PushMessageReceiver 类,实现onNotificationMessageArrived和onNotificationMessageClicked方法。

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、把DemoNotificationReceiver 注册到应用的 AndroidManifest.xml 里面

<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、拦截推送消息的点击

点击推送消息时默认会触发出下面的action 事件:

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);

这时我们可以在你的 AndroidManifest.xml ⾥面配置了 A activity 拦截这个 action, 那么点击时就会跳转到 activity A。

<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>

详细内容请点击:Android 推送服务开发指南

猜你喜欢

转载自blog.csdn.net/zwl5670/article/details/52381950