无法从推送通知中获取数据

时间:2015-04-26 11:45:27

标签: android json parse-platform push-notification

我正在尝试使用此代码添加特定信息:

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"}

但我得到的是:

public class MBoolean() {
var internal: Boolean = false

constructor(b: Boolean) : this() {
    internal = b
}

fun set(b: Boolean) {
    internal = b
}

fun get(): Boolean {
    return internal
}
}

public class MInt() {
private var internal: Int = 0

constructor(i: Int) : this() {
    set(i)
}

public fun set(i: Int) {
    internal = i
}

public fun get(): Int {
    return internal
}
}

override fun writeToParcel(p: Parcel, flags: Int) {
    parcelBooleans.forEach { p.writeBoolean(it.get()) }
    parcelInts.forEach { p.writeInt(it.get()) }
}

private fun readFromParcel(p: Parcel) {
    parcelBooleans.forEach { it.set(p.readBoolean()) }
    parcelInts.forEach { it.set(p.readInt()) }
}

我正在互联网上找一个解决方案,却找不到一个。

任何想法?

1 个答案:

答案 0 :(得分:1)

如果你没有得到“测试”字段而不是你可以做的是将“message”字段的json对象添加到它的字段中,如下所示: -

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对象