我有一个 GCM 监听器,一切都很好,除了我在 GCM 消息( bundle 数据)中有一个参数(键,值),并且无法使用他的 get 方法检索特定键,我必须“patch”(或重试)返回的值,如下所示:
// this can't retrieve the value,
// example: "id" in message is = 123, intValue gets 0 (default value for int)
int intValue = data.getInt("id");
if (intValue == 0) {
// but this way can catch the int value,
// example: "id" in message is = 123, intValue gets 123;
intValue = Integer.valueOf(data.getString("id"));
}
我必须“修补”数据中返回的(或检索失败的)值,
为什么会发生这种情况? (键名在两种情况下都是相同的,不应该是)
最佳答案
the main problem is i can't get the id=123 value with data.getInt("id"); but i can get the value with data.getString("id"); the rest of values and types are ok like getBoolean, get
然后您必须检查如何生成发送到 GCM 服务器的 JSON。可能您正在发送 id attr。作为字符串(带引号),这就是为什么您只能使用 getString() 读取其值
关于java - GCM Listener无法检索实际值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37467809/