java - GCM Listener无法检索实际值

标签 java android google-cloud-messaging listener

我有一个 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/

相关文章:

java - 使用 Zabbix 监控同一台机器上的两个 Java 进程

android - 如何获取LinearLayout的高度

android - 我可以为Android wear开发什么样的应用程序

node.js - 在 node.js 应用程序中接收 GCM 推送通知

android - Android GCM 注册 ID 是否始终以 "APA"开头?

java - 如何连接从 Java 中的 Kinesis Video Stream 获取的剪辑

java - 根据一个值对数字对进行排序 - Java

android - 如何消除我的适配器行布局上的间隙

Android GCM 项目 ID,哪个?

java - 如何知道 Web 请求中提供的文件