我如何通过urbanairship推送通知发送额外的数据 [英] How do I send extra data through an urbanairship push notification

查看:182
本文介绍了我如何通过urbanairship推送通知发送额外的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我需要一个推送通知发送到用户的设备。然后,当用户点击该通知,我需要我的应用程序采取具体行动。我想包括在通知操作的参数。但我不希望用户看到的参数;他们应该看到的信息。做一些研究,我发现城市飞艇网站上的以下

So I need to send a push notification to a user's device. Then when the user clicks on the notification, I need my app to take a specific action. I want to include the parameter for the action in the notification. But I don't want the user to see the parameter; they should just see the message. Doing some research, I found the following on the urban airship website

{
   "audience": "all",
   "notification": {
      "alert": "Extras example",
      "android": {
        "extra": {
            "url": "http://example.com",
            "story_id": "1234",
            "moar": "{\"key\": \"value\"}"
         }
      }
   },
   "device_types": ["android"]
}

所以我假设的警报部分是用户看到的内容。而且,根据机器人部分可能是参数。 所以我的问题是,在Java中了,我怎么看这些额外的部分?,如 story_id moar

So I am supposing that the alert portion is what a user sees. And that the portion under android could be the parameters. So my question is, in Java, how do I read those extra portions? such as story_id, or moar?

推荐答案

由于没有在这里接受的答案,我想我会告诉我过得怎么样了。
我有一个扩展广播接收器应该像你,如果你是以下UrbanAirship类。在这个类中我收到通知:

Since there is no answer accepted here I thought I'll show how I am doing it. I have a class that extends BroadcastReceiver like you should if you are following UrbanAirship. In this class I recieve the notifications:

public class IntentReceiver extends BroadcastReceiver {

    private static final String logTag = "PushUA";
    private String pushToken;

    public static String APID_UPDATED_ACTION_SUFFIX = ".apid.updated";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i(logTag, "Received intent: " + intent.toString());
        String action = intent.getAction();

        if (action.equals(PushManager.ACTION_PUSH_RECEIVED)) {          

            int id = intent.getIntExtra(PushManager.EXTRA_NOTIFICATION_ID, 0);

            logPushExtras(intent);

        } else if (action.equals(PushManager.ACTION_NOTIFICATION_OPENED)) {

            Log.i(logTag, "User clicked notification. Message: " + intent.getStringExtra(PushManager.EXTRA_ALERT));

            logPushExtras(intent);

            String url= intent.getStringExtra("url"); //Here you get your extras

...

可能帮助别人:)

Might help someone:)

这篇关于我如何通过urbanairship推送通知发送额外的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆