Here are the examples of the java api class com.google.android.gms.wearable.Node taken from open source projects.
1. SendByteArrayToNode#run()
Project: ExceptionWear
File: SendByteArrayToNode.java
File: SendByteArrayToNode.java
public void run() { if ((objectArray.length / 1024) > 100) { throw new RuntimeException("Object is too big to push it via Google Play Services"); } GoogleApiClient googleApiClient = SendWearManager.getInstance(context); googleApiClient.blockingConnect(WearExceptionTools.CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS); NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(); for (Node node : nodes.getNodes()) { MessageApi.SendMessageResult result; result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), WearExceptionTools.MESSAGE_EXCEPTION_PATH, objectArray).await(); if (!result.getStatus().isSuccess()) { Log.v(WearExceptionTools.EXCEPTION_WEAR_TAG, "ERROR: failed to send Message via Google Play Services"); } } }
2. PlayNetwork#getBestNode()
Project: CrossBow
File: PlayNetwork.java
File: PlayNetwork.java
private String getBestNode(long timeOut) throws VolleyError { final String nodeCompatibilty = context.getString(R.string.crossbow_compatibility); CapabilityApi.GetCapabilityResult nodes = Wearable.CapabilityApi.getCapability(googleApiClient, nodeCompatibilty, CapabilityApi.FILTER_REACHABLE).await(timeOut, TimeUnit.MILLISECONDS); String nodeID = null; Set<Node> nodeList = nodes.getCapability().getNodes(); if (nodeList.isEmpty()) { throw new NoConnectionError(new VolleyError("No nodes found to handle the request")); } //get the nearest node for (Node node : nodeList) { if (node.isNearby()) { return node.getId(); } nodeID = node.getId(); } return nodeID; }
3. SendCommandToNode#run()
Project: BusWear
File: SendCommandToNode.java
File: SendCommandToNode.java
public void run() { if ((objectArray.length / 1024) > 100) { throw new RuntimeException("Object is too big to push it via Google Play Services"); } GoogleApiClient googleApiClient = SendWearManager.getInstance(context); googleApiClient.blockingConnect(WearBusTools.CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS); NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(); for (Node node : nodes.getNodes()) { MessageApi.SendMessageResult result; result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), path + clazzToSend.getSimpleName(), objectArray).await(); if (!result.getStatus().isSuccess()) { Log.v(WearBusTools.BUSWEAR_TAG, "ERROR: failed to send Message via Google Play Services"); } } }
4. SendByteArrayToNode#run()
Project: BusWear
File: SendByteArrayToNode.java
File: SendByteArrayToNode.java
public void run() { GoogleApiClient googleApiClient = SendWearManager.getInstance(context); googleApiClient.blockingConnect(WearBusTools.CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS); NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(); for (Node node : nodes.getNodes()) { MessageApi.SendMessageResult result; if (sticky) { result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), WearBusTools.MESSAGE_PATH_STICKY + clazzToSend.getSimpleName(), objectArray).await(); } else { result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), WearBusTools.MESSAGE_PATH + clazzToSend.getSimpleName(), objectArray).await(); } if (!result.getStatus().isSuccess()) { Log.v(WearBusTools.BUSWEAR_TAG, "ERROR: failed to send Message via Google Play Services"); } } }
5. WearMessenger#getNodes()
Project: watchpresenter
File: WearMessenger.java
File: WearMessenger.java
private Collection<String> getNodes() { HashSet<String> results = new HashSet<String>(); NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(gApiClient).await(); for (Node node : nodes.getNodes()) { results.add(node.getId()); } Log.d(Constants.LOG_TAG, "Got " + results.size() + " nodes"); return results; }
6. SearchFragment#getNodes()
Project: MoreCo
File: SearchFragment.java
File: SearchFragment.java
/** * get nodes in transmission * * @return */ private Collection<String> getNodes() { HashSet<String> results = new HashSet<String>(); NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await(); for (Node node : nodes.getNodes()) { results.add(node.getId()); } return results; }
7. Utils#getNodes()
Project: io2015-codelabs
File: Utils.java
File: Utils.java
/** * Get a list of all wearable nodes that are connected synchronously. * Only call this method from a background thread (it should never be * called from the main/UI thread as it blocks). */ public static Collection<String> getNodes(GoogleApiClient client) { Collection<String> results = new HashSet<String>(); NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(client).await(); for (Node node : nodes.getNodes()) { results.add(node.getId()); } return results; }
8. Utils#getNodes()
Project: io2015-codelabs
File: Utils.java
File: Utils.java
/** * Get a list of all wearable nodes that are connected synchronously. * Only call this method from a background thread (it should never be * called from the main/UI thread as it blocks). */ public static Collection<String> getNodes(GoogleApiClient client) { Collection<String> results = new HashSet<String>(); NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(client).await(); for (Node node : nodes.getNodes()) { results.add(node.getId()); } return results; }
9. MainActivity#getNodes()
Project: AndroidWearable-Samples
File: MainActivity.java
File: MainActivity.java
private Collection<String> getNodes() { HashSet<String> results = new HashSet<String>(); NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await(); for (Node node : nodes.getNodes()) { results.add(node.getId()); } return results; }
10. WearDispatcher#getNodes()
Project: analytics-android
File: WearDispatcher.java
File: WearDispatcher.java
private Collection<String> getNodes(GoogleApiClient googleApiClient) { HashSet<String> results = new HashSet<>(); NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(); for (Node node : nodes.getNodes()) { results.add(node.getId()); } return results; }