Java Code Examples for com.google.android.gms.wearable.Node#isNearby()

The following examples show how to use com.google.android.gms.wearable.Node#isNearby() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageApiHandler.java    From PowerSwitch_Android with GNU General Public License v3.0 6 votes vote down vote up
private String pickBestNode(Set<Node> nodes) {
    String bestNodeId = null;

    if (nodes == null) {
        return null;
    }

    // Find a nearby node or pick one arbitrarily
    for (Node node : nodes) {
        if (node.isNearby()) {
            return node.getId();
        }
        bestNodeId = node.getId();
    }
    return bestNodeId;
}
 
Example 2
Source File: IncomingRequestWearService.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
private String pickBestNodeId(Set<Node> nodes) {

        Log.d(TAG, "pickBestNodeId: " + nodes);


        String bestNodeId = null;
        /* Find a nearby node or pick one arbitrarily. There should be only one phone connected
         * that supports this sample.
         */
        for (Node node : nodes) {
            if (node.isNearby()) {
                return node.getId();
            }
            bestNodeId = node.getId();
        }
        return bestNodeId;
    }
 
Example 3
Source File: LoggingUtil.java    From APDE with GNU General Public License v2.0 5 votes vote down vote up
private static void updateBestNode(Context context) {
	bestNodeId = null;
	
	try {
		CapabilityInfo info = Tasks.await(Wearable.getCapabilityClient(context).getCapability("apde_receive_logs", CapabilityClient.FILTER_REACHABLE));
		for (Node node : info.getNodes()) {
			if (node.isNearby()) {
				bestNodeId = node.getId();
			}
		}
	} catch (Exception e) {
		// Don't call printStackTrace() because that would make an infinite loop
		Log.e("apde", e.toString());
	}
}
 
Example 4
Source File: WearDataLayerListenerService.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCapabilityChanged(CapabilityInfo capabilityInfo) {
	if ("remote_notifications".equals(capabilityInfo.getName())) {
		watchConnected = false;
		for (Node node : capabilityInfo.getNodes()) {
			if (node.isNearby())
				watchConnected = true;
		}
	}
}
 
Example 5
Source File: DisconnectListenerService.java    From android-FindMyPhone with Apache License 2.0 5 votes vote down vote up
private void updateFindMeCapability(CapabilityInfo capabilityInfo) {
    Set<Node> connectedNodes = capabilityInfo.getNodes();
    if (connectedNodes.isEmpty()) {
        setupLostConnectivityNotification();
    } else {
        for (Node node : connectedNodes) {
            // we are only considering those nodes that are directly connected
            if (node.isNearby()) {
                ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                        .cancel(FORGOT_PHONE_NOTIFICATION_ID);
            }
        }
    }
}
 
Example 6
Source File: Utils.java    From ETSMobile-Android2 with Apache License 2.0 5 votes vote down vote up
public static String getRemoteNodeId(GoogleApiClient googleApiClient) {
    NodeApi.GetConnectedNodesResult nodesResult =
            Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
    List<Node> nodes = nodesResult.getNodes();
    for (Node node : nodes) {
        if(node.isNearby()) {
            return node.getId();
        }
    }
    if (nodes.size() > 0) {
        return nodes.get(0).getId();
    }
    return null;
}
 
Example 7
Source File: WearService.java    From WearPay with GNU General Public License v2.0 5 votes vote down vote up
protected String pickBestNodeId(Set<Node> nodes) {
    String bestNodeId = null;
    // Find a nearby node or pick one arbitrarily
    for (Node node : nodes) {
        if (node.isNearby()) {
            return node.getId();
        }
        bestNodeId = node.getId();
    }
    return bestNodeId;
}
 
Example 8
Source File: WatchUpdaterService.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
private String pickBestNodeId(Set<Node> nodes) {
    String bestNodeId = null;
    // Find a nearby node or pick one arbitrarily
    for (Node node : nodes) {
        if (node.isNearby()) {
            return node.getId();
        }
        bestNodeId = node.getId();
    }
    return bestNodeId;
}
 
Example 9
Source File: ListenerService.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
private Node pickBestNode(Set<Node> nodes) {
    Node bestNode = null;
    // Find a nearby node or pick one arbitrarily
    for (Node node : nodes) {
        if (node.isNearby()) {
            return node;
        }
        bestNode = node;
    }
    return bestNode;
}
 
Example 10
Source File: GoogleApiMessenger.java    From Sensor-Data-Logger with Apache License 2.0 5 votes vote down vote up
public static List<Node> getNearbyNodes(List<Node> nodes) {
    List<Node> nearbyNodes = new ArrayList<>();
    for (Node node : nodes) {
        if (node.isNearby()) {
            nearbyNodes.add(node);
        }
    }
    return nearbyNodes;
}
 
Example 11
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private Node pickBestNode(Set<Node> nodes) {
    Node bestNode = null;
    // Find a nearby node or pick one arbitrarily
    for (Node node : nodes) {
        if (node.isNearby()) {
            return node;
        }
        bestNode = node;
    }
    return bestNode;
}
 
Example 12
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private String pickBestNodeId(Set<Node> nodes) {//TODO remove once confirm not needed
    String bestNodeId = null;
    // Find a nearby node or pick one arbitrarily
    for (Node node : nodes) {
        if (node.isNearby()) {
            return node.getId();
        }
        bestNodeId = node.getId();
    }
    return bestNodeId;
}
 
Example 13
Source File: WatchUpdaterService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private String pickBestNodeId(Set<Node> nodes) {
    String bestNodeId = null;
    // Find a nearby node or pick one arbitrarily
    for (Node node : nodes) {
        if (node.isNearby()) {
            return node.getId();
        }
        bestNodeId = node.getId();
    }
    return bestNodeId;
}
 
Example 14
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private Node pickBestNode(Set<Node> nodes) {
    Node bestNode = null;
    // Find a nearby node or pick one arbitrarily
    for (Node node : nodes) {
        if (node.isNearby()) {
            return node;
        }
        bestNode = node;
    }
    return bestNode;
}
 
Example 15
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private String pickBestNodeId(Set<Node> nodes) {//TODO remove once confirm not needed
    String bestNodeId = null;
    // Find a nearby node or pick one arbitrarily
    for (Node node : nodes) {
        if (node.isNearby()) {
            return node.getId();
        }
        bestNodeId = node.getId();
    }
    return bestNodeId;
}
 
Example 16
Source File: MainActivity.java    From react-native-android-wear-demo with MIT License 5 votes vote down vote up
@Override
protected String doInBackground(GoogleApiClient... params) {
  final List<Node> connectedNodes = Wearable.NodeApi.getConnectedNodes(client).await().getNodes();
  for (Node connectedNode : connectedNodes) {
    if (connectedNode.isNearby()) {
      return connectedNode.getId();
    }
  }
  return null;
}
 
Example 17
Source File: WearDataLayerListenerService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCapabilityChanged(CapabilityInfo capabilityInfo){
	if("remote_notifications".equals(capabilityInfo.getName())){
		watchConnected=false;
		for(Node node:capabilityInfo.getNodes()){
			if(node.isNearby())
				watchConnected=true;
		}
	}
}
 
Example 18
Source File: WearDataLayerListenerService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCapabilityChanged(CapabilityInfo capabilityInfo){
	if("remote_notifications".equals(capabilityInfo.getName())){
		watchConnected=false;
		for(Node node:capabilityInfo.getNodes()){
			if(node.isNearby())
				watchConnected=true;
		}
	}
}
 
Example 19
Source File: MainWearActivity.java    From wear-os-samples with Apache License 2.0 5 votes vote down vote up
private String pickBestNodeId(Set<Node> nodes) {

        String bestNodeId = null;
        // Find a nearby node or pick one arbitrarily.
        for (Node node : nodes) {
            if (node.isNearby()) {
                return node.getId();
            }
            bestNodeId = node.getId();
        }
        return bestNodeId;
    }
 
Example 20
Source File: PlayNetwork.java    From CrossBow with Apache License 2.0 4 votes vote down vote up
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;
}