I have the following block of code to sent a message to my device, but the message is not getting sent... I do not have any idea why...
Here is the code in which I build my 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();
And here is my code that is getting called from the sendMessage method:
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
}
}
});
The logging is here:
Google API Client connected
message could not be sent: Status{statusCode=unknown status code: 4004, resolution=null}
Client connected: true
So all conditions seem to be fine, but the unknown error code 4004 cannot be resolved (at least I did not find anything wrong so far). Anyone an idea what could be the reason of this?
Dirk
I've found a documentation that supports my previous assumptions from comment above. Please take a look at WearableStatusCodes
class - it contains status codes used in WearableApi method results.
https://developer.android.com/reference/com/google/android/gms/wearable/WearableStatusCodes.html#INVALID_TARGET_NODE
So this error is no longer "unknown":) - 4004
is a code for INVALID_TARGET_NODE
.
Please check what value you pass in nodeId
variable.