- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在为我的一个应用程序集成护目镜云消息传递。从服务器,我发送键值对为:
'not_id' => 1000,
'title' => 'This is a title. title',
'vibrate' => 1,
'sound' => 1
在安卓 GCMIntentService 中:
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
// The getMessageType() intent parameter must be the intent you received
// in your BroadcastReceiver.
String messageType = gcm.getMessageType(intent);
if (!extras.isEmpty()) {
int not_id=extras.getInt("not_id");
在提取key not_id(整数)的值时,抛出如下异常:
Key not_id expected Integer but value was a java.lang.String.java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
gcm 是否将所有值都转换为字符串?
徒劳地浏览了文档。我做错了什么吗?
最佳答案
我遇到了同样的问题。我发现的解决方法是将我们创建的 json 字符串化,并将整个 json 作为键值对添加到我们发送到 gcm 云服务器的数据对象中 -
通常我们发送什么 -
myData: {
'title' : 'New Notification',
'myAge' : 25
}
json: {
'to': to,
'data': myData
}
这样,数据包中的所有值都被转换为字符串。上面的数据25被转换成String。
我这样做的方式 -
json: {
'to': to,
'data': {'myData' : myData}
}
现在 25 仍将是 Integer 。
注意 - 在发送之前将 myData JsonObject 字符串化。在 Javascript 中,我使用 JSON.stringify(myData);
然后在 Android 端我们可以检索整个 json -
@Override
public void onMessageReceived(String from, Bundle data) {
try {
JSONObject myData = new JSONObject(data.getString("myData"));
} catch (JSONException e){}
}
现在所有检索到的值都将是它们的原始类型。
关于java - 谷歌云消息 : Payload value always string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31726593/
概述 我想实现一个 Lucene 索引器/搜索器,它使用新的有效负载功能,允许向文本添加元信息。在我的具体情况下,我向概念标签添加权重(可以理解为 % 概率,介于 0 到 100 之间),以便使用它们
我正在分析一个 metasploit 漏洞 here我试图弄清楚 payload.encoded 中的 payload 来自第 358 行。我是开发开发的新手,但基本的编程规则说 payload 应该
我从我的 javascript 发送交易 Metamask 打开传输对话框 我确定 i get an error message in metamask (inpage.js:1 MetaMask -
action.payload 何时、何地以及为什么被调用?请任何人帮助我了解action.payload的实际用途是什么。我已经搜索了很多网站,但我不明白.. 最佳答案 当您处理请求时,例如单击我们需
我用 Angular 编写代码,在一种情况下,json 返回一个值(如有效负载),我需要对其进行解密。我有一个这样的有效载荷: 我需要解码它。像下面的方式:例如,$B 部分的值我只需要 14,$s 的
我正在编写一个进行服务调用的 Chrome 扩展。 当我发出同源 POST ajax 请求时,我的数据对象以 JSON 格式传递: $.ajax(sameOriginURL, { data
如何在连接语句的 lambda 中访问信号的“有效负载”? 假设信号看起来像这样: signals: void stateChanged(std::pair); 现在在 connect 语句中,我
我正在尝试使用 RestSharp 来使用查询 rest,但我总是收到 Bad Request 响应。代码: var url = "https://gql.tokopedia.com/graphql/
在 Android GCM 文档中,据说有效载荷最大为 4096 字节限制。 payload的4096字节是否包括registration_id长度?我发现我可以发送有效载荷为 16038 字节(包括
前言 做过前后端联调的小伙伴,可能有时会遇到一些问题。例如,我明明传递数据给后端了,后端为什么说没收到呢?这时候可能就会就会有小伙伴陷入迷茫,本文从chrome-dev-tools(F12调试器)中看
我将 JSON 提供给某个网络钩子(Hook)以触发通知 (M$ Teams)。这很好用。但是,我想扩展我的 Perl 脚本:我需要在特定条件下向我的“messagecard”构造添加一个新节点。 例
我有一个 Xamarin 项目(UWP 和 iOS)在 VS2015 中构建并运行良好。 该项目包含一些通用 Windows 和 iOS 项目,以及两个平台使用的许多 PCL(用于 View 模型、服
我正在使用 Hyperledger Fabric Java SDK 通过 txId 获取交易。返回对象包含交易信息。 TransactionInfo txInfo = channel.queryTra
我有以下代码,用于检查 token 并授权 Google 用户登录 GoogleIdToken.Payload tempPayload = token.getPayload(); if (!tempP
当我们使用 sqlmap ,它会自动执行查找网站的 sql 注入(inject) 的所有操作。我感兴趣的是我直接在我的浏览器中发送恶意查询并在其中获取结果,但是当我找不到任何东西时,我使用 sqlma
我正在使用 Redux 和 React 从 API 加载数据。尽管成功提取数据并将其应用到状态,但它会抛出错误: Uncaught TypeError: Cannot read property 'p
我对 python 的随机函数有一个问题。我不知道哪个随机函数适用于此代码: name=['toffla','rebecca','toff','becca'] if (parser.getPayloa
在阅读了 Heartbeat 的 RFC 6520 后,我有几个问题: https://www.rfc-editor.org/rfc/rfc6520 具体来说,我不明白为什么心跳需要包含任意有效负载甚
如何用php curl发送请求负载? 我正在尝试将一个文件上传到一个免费托管文件的服务器,当将文件发送到curl时,我不接受它,我重定向到一个错误页,当我从您的interfas中执行此操作时,我可以在
我有一个非 ARC 项目,现在我在成功迁移后使用 SDK 8.1 迁移了应用程序 Xcode 6,当我尝试将其存档时,*.ipa 文件已创建,但如果我尝试通过上传应用程序diawi 或 hokey 应
我是一名优秀的程序员,十分优秀!