【问题标题】:Can't send data using Parse Push无法使用 Parse Push 发送数据
【发布时间】:2015-10-05 07:30:30
【问题描述】:

我正在尝试使用 Parse Push 向我自己的设备发送推送通知。但是,每当我尝试将 JSONObject 设置为数据时,我的设备都不会收到任何内容。我试过 setMessage() 并且它有效。知道有什么问题吗?

                ParseQuery pushQuery = ParseInstallation.getQuery();
                pushQuery.whereEqualTo("username", "abc@zzz.com");

                ParsePush push = new ParsePush();

                JSONObject obj= null;
                try {
                    obj = new JSONObject("{\"channel\":\"nom_nom_CH@\",\"cat\":\"WP\"}");
                    obj.put("action","com.parse.starter.UPDATE_STATUS");
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                push.setQuery(pushQuery);
                push.setData(obj);
                push.sendInBackground();
            }

对于接收者

@Override
public void onPushOpen(Context context, Intent intent) {
    Bundle extras = intent.getExtras();
    String jsonData = extras.getString("com.parse.Data");

    JSONObject jsonObject;
    try {
        jsonObject = new JSONObject(intent.getExtras().getString("com.parse.Data"));
        String channel = jsonObject.getString("channel");
        Log.d("Channel", channel);
    } catch (JSONException e) {
        e.printStackTrace();
    }


    Intent i = new Intent(context, Activity_Invite_nom.class);

    i.putExtras(intent.getExtras());
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i);
}

【问题讨论】:

  • 您的接收器方法是否触发?
  • @kishorejethava 如果我没有收到任何通知,我将无法触发它
  • 您可以从 Parse Data 浏览器 (GUI) 中查看通知状态,单击 Push 选项卡,您可以查看列表及其状态
  • @kishorejethava 是的,它显示在 Parse 网站上,但我的手机上没有收到任何东西
  • 如果ParseInstallation 类有频道而不是添加一行push.setChannel("channelName"); 并在你的Json 中添加Alert 消息obj.put("alert","Request from User");

标签: android json parse-platform notifications push


【解决方案1】:

我已经发现了我的代码的问题。原来我只需要实现这两行

                        data.put("alert", "" + fullname + " invited you to nom!");
                        data.put("action", Parse_Receiver.KEY_PUSH_CHANNEL);

感谢大家的帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    相关资源
    最近更新 更多