融云--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 推送服务开发指南

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

少华年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值