我有一个应用程序,可以与我的LG G手表进行通信。问题是我无法发送消息回来。以下是从可穿戴设备发送的代码,它始终指示已发送消息:
public void oops(View view){
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
for (Node node : nodes.getNodes()) {
MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), "/start/MainActivity", "Hello".getBytes()).await();
if (!result.getStatus().isSuccess()) {
Log.e("INFO", "ERROR");
} else {
Log.i("INFO", "Success sent to: " + node.getDisplayName());
}
}
}
});
thread.start();
}
我每次发送后都会收到成功的消息。这是另一端的接收器服务:
public class Reciever extends Service implements MessageApi.MessageListener {
public Reciever() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void onMessageReceived(MessageEvent messageEvent) {
Log.i("INFO", "We got it!");
}
}
这是我在手表应用中使用的完全相同的代码,可以正常接收消息。我确定服务已经正确启动和声明,并且两个应用程序具有相同的ID。有什么建议吗?