我有一个基本的Android Wear应用程序,它成功地使用可穿戴数据层在移动设备和Wear之间发送和接收消息。
然而,每当我(从移动或穿戴设备)发送消息时,另一端都会多次收到(比如5-17之间的任何地方)。为什么不只是收到一次?据我所知,它只发送一次。
成功连接后,以下是我的
发送消息的代码
(两端相同):
private void sendMsgToWear(final String strMsg){
new AsyncTask<Void, Void, List<Node>>(){
@Override
protected List<Node> doInBackground(Void... params) {
return getNodes();
}
@Override
protected void onPostExecute(List<Node> nodeList) {
for(Node node : nodeList) {
Log.v("DEVELOPER", "......Phone: Sending Msg: " + strMsg + " to node: " + node.getId());
PendingResult<MessageApi.SendMessageResult> result = Wearable.MessageApi.sendMessage(
mGoogleApiClient,
node.getId(),
strMsg,
null
);
result.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
@Override
public void onResult(MessageApi.SendMessageResult sendMessageResult) {
Log.v("DEVELOPER", "......Phone: " + sendMessageResult.getStatus().getStatusMessage());
}
});
}
}
}.execute();
}
private List<Node> getNodes() {
List<Node> nodes = new ArrayList<Node>();
NodeApi.GetConnectedNodesResult rawNodes =
Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
for (Node node : rawNodes.getNodes()) {
nodes.add(node);
nodeID = node.getId();
}
return nodes;
}
这就是我
接收
在实现MessageApi.MessageListener的活动上:
@Override
public void onMessageReceived(MessageEvent messageEvent) {
Log.d("DEVELOPER", "......Wear: successfully received phone to wear communication!");
}
发送端的输出如下:
07-11 10:54:57.646 26920-28711/com.wearTest.message V/DEVELOPERï¹ ......Phone: Sending Msg: testMessage to node: 6ecc099a-60f8-4c3d-90fe-fa2f248c6bf7
07-11 10:54:57.666 26920-26920/com.wearTest.message V/DEVELOPERï¹ ......Phone: null
接收侧日志:
07-11 10:54:57.962 5509-5672/com.wearTest.message D/DEVELOPERï¹ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.962 5509-5610/com.wearTest.message D/DEVELOPERï¹ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.962 5509-5660/com.wearTest.message D/DEVELOPERï¹ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.962 5509-5521/com.wearTest.message D/DEVELOPERï¹ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.962 5509-5539/com.wearTest.message D/DEVELOPERï¹ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.972 5509-5570/com.wearTest.message D/DEVELOPERï¹ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.972 5509-5604/com.wearTest.message D/DEVELOPERï¹ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.972 5509-5601/com.wearTest.message D/DEVELOPERï¹ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.972 5509-5566/com.wearTest.message D/DEVELOPERï¹ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.972 5509-5520/com.wearTest.message D/DEVELOPERï¹ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.972 5509-5582/com.wearTest.message D/DEVELOPERï¹ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.972 5509-5567/com.wearTest.message D/DEVELOPERï¹ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.982 5509-5587/com.wearTest.message D/DEVELOPERï¹ ......Wear: successfully received phone to wear communication!
07-11 10:54:58.002 5509-5581/com.wearTest.message D/DEVELOPERï¹ ......Wear: successfully received phone to wear communication!
07-11 10:54:58.052 5509-5581/com.wearTest.message D/DEVELOPERï¹ ......Wear: successfully received phone to wear communication!
07-11 10:54:58.052 5509-5587/com.wearTest.message D/DEVELOPERï¹ ......Wear: successfully received phone to wear communication!
07-11 10:54:58.062 5509-5570/com.wearTest.message D/DEVELOPERï¹ ......Wear: successfully received phone to wear communication!
提前感谢!