自定义推送点击事件
本文描述了 IMLib 和 IMKit 处理用户点击远程通知(Remote notifications)的默认行为,以及应用程序如何自行处理远程推送通知的点击事件。
本文仅描述远程推送通知点击事件的处理方案。如果您需要处理 IMKit 的本地通知的点击事件,请参考本地通知点击事件处理。如果您不清楚如何区分本地通知与远程推送,可阅读知识库文档 如何理解即时通讯业务中的实时消息、本地通知和远程推送(Android)。
实现 SDK 默认跳转行为
IMLib 和 IMKit 默认处理远程推送通知的点击事件。用户点击通知时,SDK 会发出对应的隐式 Intent。您需要在 App 的应用清单文件(AndroidManifest.xml
)配置添加 Intent-filter,以接收 Intent,完成默认跳转动作。
- 来自一个联系人的通知:用户点击来自一个联系人发来一条或多条通知时,SDK 默认跳转到会话 Activity。
- 来自多个联系人的折叠通知:多个联系人发来多条通知时,这些通知会折叠 显示。用户点击来自多个联系人的通知时,SDK 默认跳转到会话列表 Activity。
- 不落地推送的通知:当用户点击不落地推送的通知时,SDK 也会发出隐式 Intent。您可以自行决定接收该 Intent 的 Activity。
跳转到与消息对应的会话页面
用户点击来自一个联系人发来一条或多条通知时,SDK 默认发出跳转到会话 Activity 的 Intent。
在 AndroidManifest.xml
的会话 Activity 中配置如下 intent-filter
即可跳转到会话 Activity。如果自定义了会话 Activity,需要替换 会话 activity
为自定义 Activity 的类名。
<activity
android:name="RongConversationActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="${applicationId}"
android:pathPrefix="/conversation"
android:scheme="rong" />
</intent-filter>
</activity>
跳转到会话列表页面
多个联系人发来多条通知时,这些通知会折叠显示。用户点击来自多个联系人的通知时,SDK 默认发出跳转到会话列表 Activity 的 Intent。
在 AndroidManifest.xml
的会话列表 Activity 中配置如下 intent-filter
即可跳转到当前 Activity。如果自定义了会话列表 Activity,需要替换 RongConversationListActivity
为自定义 Activity 的类名。
<activity
android:name="RongConversationListActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="${applicationId}"
android:pathPrefix="/conversationlist"
android:scheme="rong" />
</intent-filter>
</activity>
处理不落地通知点击跳转
通过融云发起的不落地通知会独立显示。用户点击不落地通知时,SDK 默认发出 Intent。
在 AndroidManifest.xml
进行如下配置,即可跳转到您指定的 Activity。
<activity
android:name="自定义 activity"
android:exported="true"
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="${applicationId}"
android:pathPrefix="/push_message"
android:scheme="rong" />
</intent-filter>
</activity>