我有以下代码块将消息发送到我的设备,但消息未被发送...我不知道为什么......
以下是我构建GoogleApiClient的代码:
mClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(new ConnectionCallbacks() {
@Override
public void onConnected(Bundle bundle) {
Log.d("dirk", "Google API Client connected");
sendMessage();
}
@Override
public void onConnectionSuspended(int cause) {
Log.d("dirk", "Google API Client disconnected, cause: " + cause);
mConnected = false;
mConnecting = false;
// TODO handle disconnect
}
})
.addOnConnectionFailedListener(new OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult result) {
Log.d("dirk", "Google API Client connection failed, reason: " + result);
mConnected = false;
mConnecting = false;
// TODO handle connection failure
}
})
.addApi(Wearable.API)
.build();
这是我从sendMessage方法调用的代码:
Wearable.MessageApi.sendMessage(getClient(), nodeId, PATH, null).setResultCallback(new ResultCallback<SendMessageResult>() {
@Override
public void onResult(SendMessageResult sendMessageResult) {
if (!sendMessageResult.getStatus().isSuccess()) {
Log.d("dirk", "message could not be sent: " + sendMessageResult.getStatus().toString());
Log.d("dirk", "Client connected: " + getClient().isConnected());
// TODO show communication error
}
}
});
日志记录在这里:
Google API Client connected
message could not be sent: Status{statusCode=unknown status code: 4004, resolution=null}
Client connected: true
因此所有条件似乎都很好,但未知错误代码4004无法解决(至少到目前为止我没有发现任何错误)。 任何人都知道这可能是什么原因?
德克
答案 0 :(得分:1)
我发现了一份支持我之前评论的文档。请查看WearableStatusCodes
类 - 它包含WearableApi方法结果中使用的状态代码。
https://developer.android.com/reference/com/google/android/gms/wearable/WearableStatusCodes.html#INVALID_TARGET_NODE
因此,此错误不再是&#34;未知&#34; :) - 4004
是INVALID_TARGET_NODE
的代码。
请检查您在nodeId
变量中传递的值。