我使用此方法在我的Android应用中发送上游gcm消息。
public void sendXMPPMessage(final int action, final DtoAble payload, final String messageId, final int retries) {
ThreadPool.run(new Runnable() {
@Override
public void run() {
boolean success;
int retry = 0;
do {
try {
XMPPClientMessage message = new XMPPClientMessage(action, getXMPPAuthentication(),
payload.toDto());
Bundle bundle = new Bundle();
bundle.putString(GCM.XMPP_FIELD_DATA, Json.toJson(message));
mGcm.send(GCM.USER_AT_SERVER, messageId, bundle);
mGcm.close();
success = true;
} catch (IOException e) {
Log.e(TAG, e.getMessage());
success = false;
}
} while (!success && ++retry <= retries);
if (!success) {
broadcastNack(messageId);
}
}
});
}
我有两个设备,一个在Lollipop上运行,另一个在ICS上运行。它适用于棒棒糖设备,有时也适用于ICS。问题是,当它在ICS上失败时,我没有机会知道它已经失败也没有原因。没有抛出异常,服务器没有收到任何东西。我做错了什么?
每次我发送一些东西,我都会得到这个日志输出:
GcmService start Intent {act = com.google.android.gcm.intent.SEND flg = 0x10 pkg = com.google.android.gms cmp = com.google.android.gms / .gcm.GcmService(有额外内容) com.google.android.gcm.intent.SEND
我不断获取日志输出,如:
08-14 16:57:52.596 517-30365 /? I / GCM:GCM消息com.myapp.android 0:1439560671790038%23407868f9fd7ecd
08-14 16:58:02.756 517-30365 /? I / GCM:GCM消息com.myapp.android 0:1439560681812929%23407868f9fd7ecd
08-14 16:58:12.556 517-30365 /? I / GCM:GCM消息com.myapp.android 0:1439560691789966%23407868f9fd7ecd
08-14 16:58:22.996 517-30365 /? I / GCM:GCM消息com.myapp.android 0:1439560701783336%23407868f9fd7ecd
答案 0 :(得分:0)
您需要覆盖函数onSendError(java.lang.String, java.lang.String)
https://developers.google.com/android/reference/com/google/android/gms/gcm/GcmListenerService.html#onSendError(java.lang.String,java.lang.String)