百度推送,使用了百度的开发文档的Demo,在FrontiaPushMessageReceiver的类中的
onNotificationClicked的方法中含有三个参数,只能得到前两个,而后一个始终为null,
但是在后台推送的消息中包含了三个参数,是什么原因导致第三个参数为空?
参考一下这个例子
接收推送
功能描述
接收推送消息和通知,以及接口start、stop、setTags、deleteTags和listTags的返回值,开发者要实现一个FrontiaPushMessageReceiver的子类,并在AndroidManifest.xml中声明它。
类
FrontiaPushMessageReceiver
回调介绍
onBind:FrontiaPush.start绑定云推送的回调
onUnbind:FrontiaPush.stop断开与云推送的绑定的回调
onSetTags:FrontiaPush.setTags的回调
onDelTags:FrontiaPush.deleteTags的回调
onListTags:FrontiaPush.listTags的回调
onMessage:接收推送消息的回调
onNotificationClicked:接收推送通知的回调
开发示例
package com.company;
//子类的实现
public class MyPushMessageReceiver extends FrontiaPushMessageReceiver {
//FrontiaPush.start() 的回调函数
public void onBind(Context context, Intent intent, String content, int errorCode, String appid, String userId,
String channelId, String requestId){
}
//FrontiaPush.stop() 的回调函数
public void onUnbind(Context context, Intent intent, String content, int errorCode, String requestId){
}
//FrontiaPush.setTags() 的回调函数
public void onSetTags(Context context, Intent intent, String content, int errorCode, List successTags,
List failTags, String requestId){
}
//FrontiaPush.deleteTags() 的回调函数
public void onDelTags(Context context, Intent intent, String content,
int errorCode, List successTags, List failTags, String requestId){
}
//FrontiaPush.listTags() 的回调函数
public void onListTags(Context context, Intent intent, String content,
int errorCode, List tags, String requestId){
}
//接收推送消息的回调函数
public void onMessage(Context context, Intent intent, String message, String customContentString){
}
//接收推送通知的回调函数
public void onNotificationClicked(Context context, Intent intent,
String title, String description, String customContentString){
}
}
首先,这个跳转的跳转部分在这个位置写是无效的,跳转的方式是服务端决定的,详细见百度官方:
http://push.baidu.com/doc/java/api
http://push.baidu.com/doc/restapi/msg_struct,
第一个链接中以:PushMsgToSingleDeviceRequest类的实例对象
该类包含的成员变量:
变量 类型 必需 限制 描述
channelId String 是 必须为客户端初始化成功之后返回的channelId,默认null。 唯一对应一台设备
msgType Integer 否 十进制取值如下:
0:透传消息
1:通知
默认值为0 消息类型
message String 是 详细见消息/通知格式定义,默认null。 消息内容,json格式,详见通知数据格式
msgExpires Integer 否 取值:(0, 86400 x 7],默认值为3600 x 5 相对于当前时间的消息过期时间,单位为秒
deployStatus Integer 否 仅IOS应用推送时使用,默认值为null,
取值如下:
1:开发状态
2:生产状态
topicId String 否 指定的topic变量. 长度限制 1 – 128字节,
由数字,字母和下划线组成。 类别主题
deviceType Integer 否 3:Android,4:IOS 设备类型
message字段部分部分见第二链接,
{ "title" : "hello" , "description": "hello world" //必选 "notification_builder_id": 0, //可选 "notification_basic_style": 7, //可选 "open_type":0, //可选 "url": "http://developer.baidu.com", //可选 "pkg_content":"", //可选 "custom_content":{"key":"value"}, }
这个
title:通知标题,可以为空;如果为空则设为appid对应的应用名;
description:通知文本内容,不能为空;
notification_builder_id:android客户端自定义通知样式,如果没有设置默认为0;
notification_basic_style:只有notification_builder_id为0时有效,可以设置通知的基本样式包括(响铃:0x04;振动:0x02;可清除:0x01;),这是一个flag整形,每一位代表一种样式,如果想选择任意两种或三种通知样式,notification_basic_style的值即为对应样式数值相加后的值。
open_type:点击通知后的行为(1:打开Url; 2:自定义行为;); open_type = 1,url != null:打开网页; open_type = 2,pkg_content = null:直接打开应用; open_type = 2,pkg_content != null:自定义动作打开应用。
url:需要打开的Url地址,open_type为1时才有效;
pkg_content:open_type为2时才有效,Android端SDK会把pkg_content字符串转换成Android Intent,通过该Intent打开对应app组件,所以pkg_content字符串格式必须遵循Intent uri格式,最简单的方法可以通过Intent方法toURI()获取
custom_content:自定义内容,键值对,Json对象形式(可选);在android客户端,这些键值对将以Intent中的extra进行传递。
这里可以看出来了吧,服务端部分把你要跳转的部分写上去,然后可以执行跳转;而不是在android工程里面写的