2. MessageReceiver/AliyunMessageIntentService
- 通过继承MessageReciever,可以拦截通知,接收消息,获取推送中的扩展字段。或者在通知打开或删除的时候,切入进行后续处理。
- 如果调用了setPushIntentService,则需继承com.alibaba.sdk.android.push.AliyunMessageIntentService,并覆写相关方法,AliyunMessageIntentService所有消息回调同MessageReceiver一致。
使用方法:
MessageReceiver继承com.alibaba.sdk.android.push.MessageReceiver;
在Manifest中找到原来MessageReceiver的配置,将上边的class替换成你自己的receiver[不要配置多个]。
-
[backcolor=transparent]
<!--消息接收-->
- [backcolor=transparent]<receiver android:name="com.alibaba.sdk.android.push.MessageReceiver <-- 把这里替换成你自己的receiver">
- [backcolor=transparent] [backcolor=transparent]<intent-filter>
- [backcolor=transparent] [backcolor=transparent]<action[backcolor=transparent] [backcolor=transparent]android:name[backcolor=transparent]=[backcolor=transparent]"com.alibaba.push2.action.NOTIFICATION_OPENED"[backcolor=transparent]/>
- [backcolor=transparent] [backcolor=transparent]</intent-filter>
- [backcolor=transparent] ... ...
- [backcolor=transparent]</receiver>
AliyunMessageIntentService
- 继承com.alibaba.sdk.android.push.AliyunMessageIntentService并覆写相关方法
- 在Manifest中注册该service
-
[backcolor=transparent]
[backcolor=transparent]
<service[backcolor=transparent]
[backcolor=transparent]
android:name[backcolor=transparent]
=[backcolor=transparent]
"MyPushIntentService"[backcolor=transparent]
[backcolor=transparent]
>
- [backcolor=transparent] [backcolor=transparent]<intent-filter>
- [backcolor=transparent] [backcolor=transparent]<action[backcolor=transparent] [backcolor=transparent]android:name[backcolor=transparent]=[backcolor=transparent]"com.alibaba.push2.action.NOTIFICATION_OPENED"[backcolor=transparent] [backcolor=transparent]/>
- [backcolor=transparent] [backcolor=transparent]</intent-filter>
- [backcolor=transparent] [backcolor=transparent]<intent-filter>
- [backcolor=transparent] [backcolor=transparent]<action[backcolor=transparent] [backcolor=transparent]android:name[backcolor=transparent]=[backcolor=transparent]"com.alibaba.push2.action.NOTIFICATION_REMOVED"[backcolor=transparent] [backcolor=transparent]/>
- [backcolor=transparent] [backcolor=transparent]</intent-filter>
- [backcolor=transparent] [backcolor=transparent]<intent-filter>
- [backcolor=transparent] [backcolor=transparent]<action[backcolor=transparent] [backcolor=transparent]android:name[backcolor=transparent]=[backcolor=transparent]"com.alibaba.sdk.android.push.RECEIVE"[backcolor=transparent] [backcolor=transparent]/>
- [backcolor=transparent] [backcolor=transparent]</intent-filter>
- [backcolor=transparent] [backcolor=transparent]</service>
消息接收回调
- 用于接收服务端推送的消息。
- 消息不会弹窗,而是回调该方法。
参数
- context 上下文环境
- message CPushMessage类型,可以获取消息Id、消息标题和内容。
- [backcolor=transparent]void[backcolor=transparent] onMessage[backcolor=transparent]([backcolor=transparent]Context[backcolor=transparent] context[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]CPushMessage[backcolor=transparent] message[backcolor=transparent]);
通知接收回调
- 客户端接收到通知后,回调该方法。
- 可获取到并处理通知相关的参数。
参数
- context 上下文环境
- title 通知标题
- summary 通知内容
- extraMap 通知额外参数,包括部分系统自带参数:_ALIYUN_NOTIFICATION_ID_(V2.3.5及以上):创建通知对应id
- _ALIYUN_NOTIFICATION_PRIORITY_(V2.3.5及以上):创建通知对应id。默认不带,需要通过OpenApi设置
- [backcolor=transparent]void[backcolor=transparent] onNotification[backcolor=transparent]([backcolor=transparent]Context[backcolor=transparent] context[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] title[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] summary[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]Map[backcolor=transparent]<[backcolor=transparent]String[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent]>[backcolor=transparent] extraMap[backcolor=transparent])
通知打开回调
- 打开通知时会回调该方法,通知打开上报由SDK自动完成。
参数
- context 上下文环境
- title 通知标题
- summary 通知内容
- extraMap 通知额外参数,包括部分系统自带参数:_ALIYUN_NOTIFICATION_ID_(V2.3.5及以上):创建通知对应id
- _ALIYUN_NOTIFICATION_PRIORITY_(V2.3.5及以上):创建通知对应id。默认不带,需要通过OpenApi设置
- [backcolor=transparent]void[backcolor=transparent] onNotificationOpened[backcolor=transparent]([backcolor=transparent]Context[backcolor=transparent] context[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] title[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] summary[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] extraMap[backcolor=transparent]);
无跳转逻辑通知打开回调
- 打开无跳转逻辑(open=4)通知时回调该方法(v2.3.2及以上版本支持),通知打开上报由SDK自动完成。
参数
- context 上下文环境
- title 通知标题
- summary 通知内容
- extraMap 通知额外参数,包括部分系统自带参数:_ALIYUN_NOTIFICATION_ID_(V2.3.5及以上):创建通知对应id
- _ALIYUN_NOTIFICATION_PRIORITY_(V2.3.5及以上):创建通知对应id。默认不带,需要通过OpenApi设置
- [backcolor=transparent]void[backcolor=transparent] onNotificationClickedWithNoAction[backcolor=transparent]([backcolor=transparent]Context[backcolor=transparent] context[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] title[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] summary[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] extraMap[backcolor=transparent]);
通知删除回调
- 删除通知时回调该方法,通知删除上报由SDK自动完成。
参数
- context 上下文环境
- messageId 删除通知的Id
- [backcolor=transparent]void[backcolor=transparent] onNotificationRemoved[backcolor=transparent]([backcolor=transparent]Context[backcolor=transparent] context[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] messageId[backcolor=transparent]);
通知在应用内到达回调
- 当用户创建自定义通知样式,并且设置推送应用内到达不创建通知弹窗时调用该回调,且此时不调用onNotification回调(v2.3.3及以上版本支持)
参数
- context 上下文环境
- title 通知标题
- summary 通知内容
- extraMap 通知额外参数
- openType 原本通知打开方式,1:打开APP;2:打开activity;3:打开URL;4:无跳转逻辑
- openActivity 所要打开的activity的名称,仅当openType=2时有效,其余情况为null
- openUrl 所要打开的URL,仅当openType=3时有效,其余情况为null
- [backcolor=transparent]void[backcolor=transparent] onNotificationReceivedInApp[backcolor=transparent]([backcolor=transparent]Context[backcolor=transparent] context[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] title[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] summary[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]Map[backcolor=transparent]<[backcolor=transparent]String[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent]>[backcolor=transparent] extraMap[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]int[backcolor=transparent] openType[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] openActivity[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] openUrl[backcolor=transparent]);