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