我有以下代码块向我的设备发送消息,但消息没有被发送......我不知道为什么......
这是我构建 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(至少目前我没有发现任何错误)。任何人都知道这可能是什么原因?
短剑