1

我有以下代码块向我的设备发送消息,但消息没有被发送......我不知道为什么......

这是我构建 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(至少目前我没有发现任何错误)。任何人都知道这可能是什么原因?

短剑

4

1 回答 1

1

我从上面的评论中找到了支持我之前假设的文档。请查看WearableStatusCodes类 - 它包含 WearableApi 方法结果中使用的状态代码。 https://developer.android.com/reference/com/google/android/gms/wearable/WearableStatusCodes.html#INVALID_TARGET_NODE

所以这个错误不再是“未知”:) -4004INVALID_TARGET_NODE.
请检查您在nodeId变量中传递的值。

于 2014-07-14T18:19:20.050 回答