如何设置消息点击事件?
TPNS 推荐使用 Intent 方式进行跳转(注:SDK 点击消息默认支持点击事件,触发后打开主界面,如果在 onNotifactionClickedResult 设置跳转操作会与管理台/API中指定的自定义跳转冲突,导致自定义的跳转失效)。
使用 Intent 方式跳转指引:
在客户端 App 的 manifest 上,配置需要跳转的页面:
- 如要跳转 AboutActivity 指定页面,示例代码如下:
<activity
android:name="com.qq.xg.AboutActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"/>
<!-- 通过自定义 data 块内容指定您的完整 scheme,按照您的配置,将会组成形如"语义名://主机名/路径名"的 url 标识 -->
<!-- 为防止和其他应用的跳转目标页面冲突,您可以使用带有 app 名称、app 包名等可以唯一标记应用的字段进行配置-->
<data
android:scheme="语义名"
android:host="主机名"
android:path="/路径名" />
</intent-filter>
</activity>
-
若使用移动推送 TPNS 管理台设置 Intent 进行跳转,填写方式如下:
-
若使用服务端 SDK ,设置 Intent 进行跳转,可设置 Intent 为(以 Java SDK 为例):
action.setIntent("xgscheme://com.tpns.push/notify_detail");
-
若需要带上 param1 和 param2 等参数,您可以做如下设置:
action.setIntent("xgscheme://com.tpns.push/notify_detail?param1=aa¶m2=bb");
终端获取参数:
- 在您跳转指定的页面 onCreate 方法里,添加如下代码:
Uri uri = getIntent().getData();
if (uri != null) {
String url = uri.toString();
String p1= uri.getQueryParameter("param1");
String p2= uri.getQueryParameter("param2");
}
- 如果传参包含有特殊字符,如 # 、& 等,可以参考使用如下方式解析:
Uri uri = getIntent().getData();
if (uri != null) {
String url = uri.toString();
UrlQuerySanitizer sanitizer = new UrlQuerySanitizer();
sanitizer.setUnregisteredParameterValueSanitizer(UrlQuerySanitizer.getAllButNulLegal());
sanitizer.parseUrl(url);
String value1 = sanitizer.getValue("key1");
String value2 = sanitizer.getValue("key2");
Log.i("TPNS" , "value1 = " + value1 + " value2 = " + value2);
}