移动开发平台 mPaaS 使用内建消息通知

By | 2021年4月23日

在新版本的消息推送 SDK 中,mPaaS 支持内建消息通知,即:

  • 当展示类型消息(非静默消息)到达时 SDK 将自动弹出系统通知并处理跳转事件。
  • 消息到达、打开、忽略埋点由 SDK 自行处理,无需您手动调用。

启用内建消息通知

默认情况下,内建消息通知功能是关闭的。打开该功能需要您在其实现的 AliPushRcvService 子类中覆写 useDefaultNotification 方法并返回 true

  
  1. protected abstract boolean useDefaultNotification(String msgKey, String msgValue);

启用内建消息通知后,展示类型消息推送至客户端时,handleActionReceived 方法不再被调用,如果您仍希望获取消息内容,可在 useDefaultNotification 中进行处理。

通知消息跳转

当用户点击消息时,消息推送 SDK 将根据消息携带的 URL 参数进行跳转。当 URL 为 Web 网页时,浏览器将被启动被打开此 URL。当 URL 为自定义 URI 时,接入应用必须能够接收此 URI 并进行正确处理。步骤如下:

  1. AndroidManifest.xml 中声明可接收自定义 URI 的 Activity。下方代码示例中表明 LauncherActivity 可以接收 mpaas:// 的 URI。

        
    1. <activity android:name=".push.LauncherActivity"
    2. android:launchMode="singleInstance">
    3. <intent-filter>
    4. <action android:name="android.intent.action.MAIN" />
    5. <category android:name="android.intent.category.LAUNCHER" />
    6. </intent-filter>
    7. <intent-filter>
    8. <action android:name="android.intent.action.VIEW" />
    9. <category android:name="android.intent.category.BROWSABLE" />
    10. <category android:name="android.intent.category.DEFAULT" />
    11. <data android:scheme="mpaas" />
    12. </intent-filter>
    13. </activity>
  2. 在 Activity 中处理通知消息的 Intent 对象,可通过 Intent.getData() 方法获取 URI 并进行跳转。通知消息携带的额外参数可通过 Intent.getStringExtra("data") 获取。

注意事项

SDK 使用的消息通知 ID 从 10000 开始,请避免您使用的其他通知栏消息 ID 与 SDK 使用的消息通知 ID 冲突。

请关注公众号获取更多资料

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注