2

I'm following the android wear documentation to send messages from one device to another (https://developer.android.com/training/wearables/data-layer/messages.html)

but I think there's some error in the examples because the send message method throws an IllegalStateException with the following message: await must not be called on the UI thread

How can I fix it?

basteez
  • 477
  • 1
  • 5
  • 15

2 Answers2

5

Instead of calling .await(), use .setResultCallback(). For example, ...

result.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
            @Override
            public void onResult(MessageApi.SendMessageResult sendMessageResult) {
                Log.v(TAG, "Sent message");
            }
        });
gatlingxyz
  • 781
  • 6
  • 12
1

You can't do that because await() blocks the thread.

You want to do this using an asynchronous thread, using for example an AsyncTask, like suggested in the Google Play Services documentation here: https://developer.android.com/google/auth/api-client.html#Sync

And yes, the documentation should be updated to explicate to do tha same for the Wear Api.

Mariux
  • 494
  • 6
  • 19