java - Request - Response API for Android Wear 2.0? -
how implement request-response protocol android wear 2.0 app?
scenario:
when tap on button on watch, want fetch data phone , display on watch's screen.
what tried:
i implemented working example using messageapi
, don't it. send dummy "request" in 1 place using 1 method, disregard pendingresult
, hope receive message corresponding response.
ideally, i'd have is:
byte[] responsebytes = sendrequest(somerequestbytes);
i'm not sure have tried.
but code should work send byte array.
wearable.messageapi.sendmessage(googleapiclient, transcriptionnodeid, voice_transcription_message_path, voicedata).setresultcallback( new resultcallback() { @override public void onresult(sendmessageresult sendmessageresult) { if (!sendmessageresult.getstatus().issuccess()) { // failed send message } } } );
voicedata simple byte array. array received both wearable , handheld device.
https://developer.android.com/training/wearables/data-layer/messages.html
to retrieve data use this:
@override public void onmessagereceived(messageevent messageevent) { if (messageevent.getpath().equals(your_text)) { messageevent.getdata();//this byte array } }
Comments
Post a Comment