使用场景
当订阅者单击您的通知时,可以根据您的配置跳转至指定的应用内页面、H5、Deeplink 等,来满足您在不同场景下的需求。
适用范围
平台 | 支持类型 |
Android | Intent 方式跳转:点击通知可以跳转至指定应用内页面,并且可以携带自定义参数 打开应用:单击通知可以直接进入 App 主页面 URL:单击通知可以打开浏览器进入指定的网页 应用内 Activity:单击通知可以跳转至指定应用内页面 |
Harmony | 打开应用页面 打开自定义页面 |
iOS | 单击通知默认是打开 App 根据下发的自定义 key 和 value 来做相应业务逻辑 |
Android 使用
注意
SDK 单击消息默认支持单击事件,触发后打开目标界面,如果在 onNotificationClickedResult 设置跳转操作会与管理台/ API 中指定的自定义跳转冲突,导致自定义的跳转失效。
SDK 配置
如果使用 Intent 方式跳转,请首先在客户端 App 的 AndroidManifest 文件内,配置需要跳转的页面:
如需跳转 AboutActivity 指定页面,示例代码如下:
<activityandroid:name="com.qq.xg.AboutActivity"android:theme="@android:style/Theme.NoTitleBar.Fullscreen" ><!-- 其他 intent-filter --><!-- <intent-filter> ... </intent-filter> --><!-- AndroidManifest 支持为一个安卓组件配置多个 intent-filter,请将自定义跳转配置添加在单独 intent-filter 内 --><intent-filter ><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT"/><!-- 自定义 data 块内容以指定您的完整 scheme --><!-- 按照您的配置,将会组成形如"语义名://主机名/路径名"的 url 标识 --><!-- 建议使用带有 app 名称、包名等可以唯一标记应用的字段进行配置,防止和其他应用的跳转目标页面冲突 --><dataandroid:scheme="语义名"android:host="主机名"android:path="/路径名" /></intent-filter></activity>
控制台使用
使用 Intent 方式跳转(推荐)


打开应用
控制台推送默认是选择打开应用。
跳转至 URL


跳转至应用内 Activity
该方式后续将下线,不建议使用。在高级设置 > 点击打开中填写如下:


REST API 使用
在推送消息体中,
body.message.android
下添加 action
和 action_type
字段,属性如下:字段名 | 类型 | 父项目 | 默认值 | 必需 | 参数描述 |
action | Object | Android | 有 | 否 | 设置点击通知栏之后的行为,默认为打开 App |
action_type | Integer | Action | 有 | 否 | 单击动作类型: 1:打开 activity 或 App 本身 2:打开浏览器 3:打开 Intent(推荐 配置指引) |
使用 Intent 方式跳转(推荐)
完整的消息示例如下:
{"audience_type": "token","token_list": ["04xxx993"],"message_type": "notify","message":{"title": "xxx","content": "xxx","android": {"action": {"action_type": 3, // 动作类型,1,打开 activity 或 App 本身;2,打开浏览器;3,打开 Intent"intent": "xgscheme://com.tpns.push/notify_detail" //SDK 版本需要大于等于1.0.9,然后在客户端的intent配置 data 标签,并设置 scheme 属性}}}}
若需要带上 param1 和 param2 等业务自定义参数,您可以做如下设置:
{"audience_type": "token","token_list": ["04xxx993"],"message_type": "notify","message":{"title": "xxx","content": "xxx","android": {"action": {"action_type": 3, // 动作类型,1:打开 activity 或 App 本身;2:打开浏览器;3:打开 Intent"intent": "xgscheme://com.tpns.push/notify_detail?param1=aa¶m2=bb" //SDK 版本需要大于等于1.0.9,然后在客户端的 intent 配置 data 标签,并设置 scheme 属性}}}}
说明
打开应用
完整的消息示例如下:
{"audience_type": "token","token_list": ["04xxx993"],"message_type": "notify","message":{"title": "xxx","content": "xxx","android": {"action": {"action_type": 1 // 动作类型,1:打开 activity 或 App 本身;2:打开浏览器;3:打开 Intent}}}}
跳转至 URL
完整的消息示例如下:
{"audience_type": "token","token_list": ["04xxx993"],"message_type": "notify","message":{"title": "xxx","content": "xxx","android": {"action": {"action_type": 2, // 动作类型,1:打开 activity 或 App 本身;2:打开浏览器;3:打开 Intent"browser": {"url": "http://tpns.qq.com", // 仅支持http、https"confirm": 1 // 是否需要用户确认}}}}}
打开应用内 Activity
完整的消息示例如下:
{"audience_type": "token","token_list": ["04xxx993"],"message_type": "notify","message":{"title": "xxx","content": "xxx","android": {"action": {"action_type": 1, // 动作类型,1:打开 activity 或 App 本身;2:打开浏览器;3:打开 Intent"activity": "com.x.y.MainActivity","aty_attr": {// activity 属性,只针对 action_type=1 的情况"if": 0, // Intent 的 Flag 属性"pf": 0 // PendingIntent 的 Flag 属性}}}}}
客户端获取参数
1. 在您跳转指定的 activity 页面 onCreate 方法内,添加如下获取 intent uri 代码:
@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_temp);// ...// onCreate 内获取// 当使用 intent uri (客户端自定义)方式推送,且在 intent 尾部添加了参数,可以通过此段代码获取各参数值。// 例如推送的 intent 值为 xgscheme://com.tpns.push/notify_detail?param1=aa¶m2=bb,// 则可以通过此段代码获取到 param1 的值 aa 和 param2 的值 bb。Uri uri = getIntent().getData();Log.i(TAG, "onCreate get data uri: " + uri);if (uri != null) {String url = uri.toString();String p1 = uri.getQueryParameter("param1");String p2 = uri.getQueryParameter("param2");}// SDK 1.3.2.0 起新增// 当创建推送任务时有填自定义参数(custom_content),可以通过此接口获取 custom_content 字符串内容。String customContent = XGPushManager.getCustomContentFromIntent(this, this.getIntent());// ...}
2. 如您的 activity 页面为应用常驻页面,例如配置了启动模式 launchMode 为 singleTop 或 singleTask,推送点击的 intent 内容将通过 activity 页面的 onNewIntent 方法触发,请同时在 onNewIntent 方法内添加如下获取 intent uri 代码。
@Overrideprotected void onNewIntent(Intent intent) {super.onNewIntent(intent);// ...// onNewIntent 内获取// 当使用 intent uri (客户端自定义)方式推送,且在 intent 尾部添加了参数,可以通过此段代码获取各参数值。// 例如推送的 intent 值为 xgscheme://com.tpns.push/notify_detail?param1=aa¶m2=bb,// 则可以通过此段代码获取到 param1 的值 aa 和 param2 的值 bb。Uri uri = intent.getData();Log.i(TAG, "onNewIntent get data uri: " + uri);if (uri != null) {String url = uri.toString();String p1 = uri.getQueryParameter("param1");String p2 = uri.getQueryParameter("param2");}// SDK 1.3.2.0 起新增// 当创建推送任务时有填自定义参数(custom_content),可以通过此接口获取 custom_content 字符串内容。String customContent = XGPushManager.getCustomContentFromIntent(this, intent);// ...}
3.如果传参包含有特殊字符,可以在创建推送时将参数值进行 URLEncode,然后在终端内使用 URLDecode 进行解析,示例如下:
Uri uri = getIntent().getData();if (uri != null) {String p1 = uri.getQueryParameter("param1");String value1 = "";try {// 自定义参数 param1 的值包含特殊字符,创建推送时可将 param1 的值进行 URLEncode;此处获取时则进行 URLDecodevalue1 = URLDecoder.decode(p1, "UTF-8");} catch (UnsupportedEncodingException e) {Log.w("移动推送", "URLDecode param failed: " + e.toString());}// 自定义参数 param2 未进行 URLEncode,直接获取即可String value2 = uri.getQueryParameter("param2");Log.i("移动推送" , "value1 = " + value1);}
Harmony 使用
SDK 配置
说明:
请确保 uris 和 actions 都单独配置 skills,若跟其他的混在一起会不生效。
{"name": "EntryAbility2","srcEntry": "./ets/entryability/EntryAbility.ets","exported": false,"skills": [ //uris 和actions单独配置skills{ "entities": [ //打开应用 "entity.system.home" ], "actions": [ "action.system.home" ] }{"actions": [ //使用uri时 actions必须要配置,否则点击通知打开uri对应ability失败"",],"uris": [{"scheme": "您应用的scheme","host": "您应用的host","path": "您应用的path"}]},{"actions": [ //actions 一定要配置,没有可以配置为空字符串"您应用的action",],}]}//示例 下面配置,推送时 uri的值填为: tpns://com.tpns.push/notify_detail{"name": "EntryAbility2","srcEntry": "./ets/entryability/EntryAbility.ets","exported": false,"skills": [{"actions": [ //使用uri时 actions必须要配置,否则点击通知打开uri对应ability失败"",],"uris": [{"scheme": "tpns", //scheme可以替换成业务自己的"host": "com.tpns.push", //host可以替换成业务自己的"path": "notify_detail" //path可以替换成业务自己的}]},{"actions": [ //actions"actions.tpns.push", //actions可以替换成业务自己的],}]}
REST API 使用
在推送消息体中,
body.message.android.harmony_message.click_action
下添加和action_type
、action
和uri
字段,属性如下:字段名 | 类型 | 父项目 | 默认值 | 必需 | 参数描述 |
action_type | int | click_action | 有 | 否 | 0:打开应用首页 1:打开自定义页面 |
action | string | click_action | 无 | 否 | 当 action_type 为1时,字段 uri 和 action 至少填写一个 应用内置页面 ability 对应的 action |
uri | string | click_action | 无 | 否 | 当 action_type 为1时,字段 uri 和action 至少填写一个 应用内置页面 ability 对应的 action |
使用自定义页面跳转
完整示例如下:
{"audience_type": "token","token_list": ["04xxx993"],"message_type": "notify","message":{"title": "xxx","content": "xxx","android": {"ring": 1,"harmony_message": {"push_type": 0,"category": "IM","slot_type": 2,"style": 3,"inbox_content": ["第一行","第二行"],"click_action": {"action_type": 1, //默认为0:打开应用首页;1:打开自定义页面"uri": "tpns://com.tpns.push/notify_detail", //当action_type为1时,字段uri和action至少填写一个"action": "actions.tpns.push" //当action_type为1时,字段uri和action至少填写一个},"custom_content":"{\\"test1\\": \\"data\\",\\"test2\\": 2}" //鸿蒙自定义参数},}}}
打开应用
完整示例如下:
{"audience_type": "token","token_list": ["04xxx993"],"message_type": "notify","message":{"title": "xxx","content": "xxx","android": {"ring": 1,"harmony_message": {"push_type": 0,"category": "IM","slot_type": 2,"style": 3,"inbox_content": ["第一行","第二行"],"click_action": {"action_type": 0 //默认为0:打开应用首页;1:打开自定义页面},"custom_content":"{\\"test1\\": \\"data\\",\\"test2\\": 2}" //鸿蒙自定义参数},}}}
iOS 使用
用户可以在通知中携带自定义参数字段下发,通过解析客户端获取的参数自行实现跳转或者其他业务逻辑。
控制台使用
REST API 使用
在推送消息体中,
body.message.ios
下添加 custom_content
字段,属性如下:字段名 | 类型 | 父项目 | 默认值 | 必需 | 参数描述 |
custom_content | String | ios | 无 | 否 | 自定义下发的参数,需要序列化为 json string |
完整的消息示例如下:
{"audience_type": "token","environment": "dev","token_list": ["0250df875c93c555dd3a2ba536b54fc1xxxx"],"message_type": "notify","message": {"title": "xxx","content": "xxxxxxxxx","ios": {"aps": {"alert": {"subtitle": "xxx"}},"custom_content": "{\\"key\\":\\"value\\"}"}}}
客户端获取参数
如果您通过 iOS SDK 集成,可以通过统一点击消息回调获取自定义参数,此回调方法是应用在所有状态(前台、后台、关闭)下的通知消息点击回调。
/// 统一点击回调/// @param response 如果 iOS 10+/macOS 10.14+ 则为 UNNotificationResponse,低于目标版本则为 NSDictionary/// @note移动推送SDK1.2.7.1+- (void)xgPushDidReceiveNotificationResponse:(nonnull id)response withCompletionHandler:(nonnull void (^)(void))completionHandler {NSLog(@"[移动推送Demo] click notification");if ([response isKindOfClass:[UNNotificationResponse class]]) {/// iOS10+消息体获取NSLog(@"notification dic: %@", ((UNNotificationResponse *)response).notification.request.content.userInfo);} else if ([response isKindOfClass:[NSDictionary class]]) {/// <IOS10消息体获取NSLog(@"notification dic: %@", response);}completionHandler();}