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

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

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

<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) {
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值