华为推送的自定义推送与自定义字段

来源:互联网 发布:淘宝英雄联盟 编辑:程序博客网 时间:2024/06/08 18:46

自定义字段在通知栏被点击后获取,但是应用未启动的时候点击是获取不到自定义字段的。

自定义跳转的使用:在需要跳转的页面中添加以下属性

<activity .....><intent-filter>    <action android:name="android.intent.action.VIEW" />    <category android:name="android.intent.category.DEFAULT" />    <data        android:host="com.packageName"        android:path="/notify_detail"        android:scheme="customscheme" /></intent-filter></activity>

然后在需要接受的页面中onCreat中和onNewIntent 中增加获取 Intent内容的处理。

华为自定义跳转的字段怎么填写呢?可以根据以下代码获取到intentUri,服务端可以拿到intentUri 的内容,替换msg里边的值,而服务端的json数据需要Encode编码一下才可以发送成功。

try {    JSONObject object = new JSONObject();    object.put("context", "内容");    JSONArray messagejson1 = new JSONArray();    messagejson1.put(object.toString());    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("customscheme://" +            "com.packageName/notify_detail?title= title&content=content"));    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);    intent.putExtra("msg", messagejson1.toString());    String intentUri = intent.toUri(Intent.URI_INTENT_SCHEME);} catch (Exception e) {}
原创粉丝点击