无法从推送通知中获取数据
can't get the data from push notification
我正在尝试使用此代码向推送添加特定信息:
JSONObject data;
String message = "Hey pal" + ", it looks like " + cur_user.get("realName") + " added you to the list '" + list_name + "'. press on me to check it.";
ParsePush push = new ParsePush();
try {
data = new JSONObject();
data.put("alert", message);
data.put("test", "test");
push.setQuery(query);
push.setData(data);
} catch (JSONException e1) {
e1.printStackTrace();
} finally {
push.sendInBackground();
}
在我的自定义接收器中,我这样做:
json = intent.getExtras().getString("com.parse.Data");
String channel = intent.getExtras().getString("com.parse.Channel");
try {
JSONObject jsonObject = new JSONObject(json);
Log.d("getNotification", json);
} catch (JSONException e) {
e.printStackTrace();
}
但我得到的只是:
D/getNotification﹕ {"NOTIFICATION_TYPE":1,"alert":"Hey pal, it looks like Listo App added you to the list 'fgh'. press on me to check it.","push_hash":"dfa928b7702a61d0863e1ba6df7c9595"}
我在互联网上到处寻找解决方案,但找不到。
有什么想法吗?
如果你没有得到 "test" 字段,那么你可以做的是使 json 对象成为 "message" 字段的对象,将测试添加到其中作为字段,如下所示:-
JSONObject data;
String message = "\"message\":{\"alert\":\"Hey pal" + ", it looks like " + cur_user.get("realName") + " added you to the list '" + list_name + "'. press on me to check it.\",\"test\":\"test\"}";
ParsePush push = new ParsePush();
try {
data = new JSONObject();
data.put("alert", message);
push.setQuery(query);
push.setData(data);
} catch (JSONException e1) {
e1.printStackTrace();
} finally {
push.sendInBackground();
}
以上字符串构成了一个 json 消息对象,其中包含警报和测试字段
我正在尝试使用此代码向推送添加特定信息:
JSONObject data;
String message = "Hey pal" + ", it looks like " + cur_user.get("realName") + " added you to the list '" + list_name + "'. press on me to check it.";
ParsePush push = new ParsePush();
try {
data = new JSONObject();
data.put("alert", message);
data.put("test", "test");
push.setQuery(query);
push.setData(data);
} catch (JSONException e1) {
e1.printStackTrace();
} finally {
push.sendInBackground();
}
在我的自定义接收器中,我这样做:
json = intent.getExtras().getString("com.parse.Data");
String channel = intent.getExtras().getString("com.parse.Channel");
try {
JSONObject jsonObject = new JSONObject(json);
Log.d("getNotification", json);
} catch (JSONException e) {
e.printStackTrace();
}
但我得到的只是:
D/getNotification﹕ {"NOTIFICATION_TYPE":1,"alert":"Hey pal, it looks like Listo App added you to the list 'fgh'. press on me to check it.","push_hash":"dfa928b7702a61d0863e1ba6df7c9595"}
我在互联网上到处寻找解决方案,但找不到。
有什么想法吗?
如果你没有得到 "test" 字段,那么你可以做的是使 json 对象成为 "message" 字段的对象,将测试添加到其中作为字段,如下所示:-
JSONObject data;
String message = "\"message\":{\"alert\":\"Hey pal" + ", it looks like " + cur_user.get("realName") + " added you to the list '" + list_name + "'. press on me to check it.\",\"test\":\"test\"}";
ParsePush push = new ParsePush();
try {
data = new JSONObject();
data.put("alert", message);
push.setQuery(query);
push.setData(data);
} catch (JSONException e1) {
e1.printStackTrace();
} finally {
push.sendInBackground();
}
以上字符串构成了一个 json 消息对象,其中包含警报和测试字段