Java Code Examples for com.google.android.gms.wearable.Node#getId()
The following examples show how to use
com.google.android.gms.wearable.Node#getId() .
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: IncomingRequestWearService.java From wear-os-samples with Apache License 2.0 | 6 votes |
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 2
Source File: ListenerService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
@Override public void onPeerDisconnected(Node peer) {//Deprecated with BIND_LISTENER super.onPeerDisconnected(peer); String id = peer.getId(); String name = peer.getDisplayName(); Log.d(TAG, "onPeerDisconnected peer name & ID: " + name + "|" + id); mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); if (mPrefs.getBoolean("enable_wearG5", false)) { startBtService(); } }
Example 3
Source File: Utils.java From ETSMobile-Android2 with Apache License 2.0 | 5 votes |
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 4
Source File: SendMessageTask.java From OkWear with Apache License 2.0 | 5 votes |
public SendMessageTask(@NonNull final GoogleApiClient googleApiClient, @NonNull final Node node, @Nullable final byte[] payload, @NonNull final String path, @Nullable final SendResultListener<MessageApi.SendMessageResult> listener) { this.googleApiClient = googleApiClient; this.id = node.getId(); this.payload = payload; this.path = path; this.listener = listener; }
Example 5
Source File: WearService.java From DeviceConnect-Android with MIT License | 5 votes |
public static WearService getInstance(final Node node, final WearManager mgr) { String nodeId = node.getId(); String[] serviceId = nodeId.split("-"); WearService service = new WearService(WearUtils.createServiceId(nodeId)); service.setName(WearConst.DEVICE_NAME + "(" + serviceId[0] + ")"); service.setNetworkType(NetworkType.BLE); service.addProfile(new WearCanvasProfile(mgr)); service.addProfile(new WearDeviceOrientationProfile(mgr)); service.addProfile(new WearKeyEventProfile(mgr)); service.addProfile(new WearNotificationProfile()); service.addProfile(new WearTouchProfile(mgr)); service.addProfile(new WearVibrationProfile()); return service; }
Example 6
Source File: WearService.java From WearPay with GNU General Public License v2.0 | 5 votes |
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 7
Source File: WatchUpdaterService.java From AndroidAPS with GNU Affero General Public License v3.0 | 5 votes |
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 8
Source File: WatchUpdaterService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private void setLocalNodeName() { forceGoogleApiConnect(); NodeApi.GetLocalNodeResult localnodes = Wearable.NodeApi.getLocalNode(googleApiClient).await(60, TimeUnit.SECONDS); Node getnode = localnodes.getNode(); localnode = getnode != null ? getnode.getDisplayName() + "|" + getnode.getId() : ""; UserError.Log.d(TAG, "setLocalNodeName. localnode=" + localnode); }
Example 9
Source File: WatchUpdaterService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
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 10
Source File: ListenerService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
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 11
Source File: ListenerService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
@Override public void onPeerConnected(Node peer) {//Deprecated with BIND_LISTENER super.onPeerConnected(peer); String id = peer.getId(); String name = peer.getDisplayName(); Log.d(TAG, "onPeerConnected peer name & ID: " + name + "|" + id); mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); sendPrefSettings(); if (mPrefs.getBoolean("enable_wearG5", false) && !mPrefs.getBoolean("force_wearG5", false)) { stopBtService(); ListenerService.requestData(this); } }
Example 12
Source File: WatchUpdaterService.java From xDrip with GNU General Public License v3.0 | 5 votes |
private void setLocalNodeName() { forceGoogleApiConnect(); NodeApi.GetLocalNodeResult localnodes = Wearable.NodeApi.getLocalNode(googleApiClient).await(60, TimeUnit.SECONDS); Node getnode = localnodes.getNode(); localnode = getnode != null ? getnode.getDisplayName() + "|" + getnode.getId() : ""; UserError.Log.d(TAG, "setLocalNodeName. localnode=" + localnode); }
Example 13
Source File: WatchUpdaterService.java From xDrip with GNU General Public License v3.0 | 5 votes |
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: LoggingUtil.java From APDE with GNU General Public License v2.0 | 5 votes |
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 15
Source File: ListenerService.java From xDrip with GNU General Public License v3.0 | 5 votes |
@Override public void onPeerConnected(Node peer) {//Deprecated with BIND_LISTENER super.onPeerConnected(peer); String id = peer.getId(); String name = peer.getDisplayName(); Log.d(TAG, "onPeerConnected peer name & ID: " + name + "|" + id); mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); sendPrefSettings(); if (mPrefs.getBoolean("enable_wearG5", false) && !mPrefs.getBoolean("force_wearG5", false)) { stopBtService(); ListenerService.requestData(this); } }
Example 16
Source File: MainActivity.java From react-native-android-wear-demo with MIT License | 5 votes |
@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: MainWearActivity.java From wear-os-samples with Apache License 2.0 | 5 votes |
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 18
Source File: WatchUpdaterService.java From xDrip with GNU General Public License v3.0 | 4 votes |
@Override protected Void doInBackground(Void... voids) { if (googleApiClient.isConnected()) { if (System.currentTimeMillis() - lastRequest > 20 * 1000) { // enforce 20-second debounce period lastRequest = System.currentTimeMillis(); //NodeApi.GetConnectedNodesResult nodes = // Wearable.NodeApi.getConnectedNodes(googleApiClient).await(); if (localnode == null || (localnode != null && localnode.isEmpty())) setLocalNodeName(); CapabilityApi.GetCapabilityResult capabilityResult = Wearable.CapabilityApi.getCapability( googleApiClient, CAPABILITY_WEAR_APP, CapabilityApi.FILTER_REACHABLE).await(GET_CAPABILITIES_TIMEOUT_MS, TimeUnit.MILLISECONDS); CapabilityInfo nodes; if (!capabilityResult.getStatus().isSuccess()) { Log.e(TAG, "doInBackground Failed to get capabilities, status: " + capabilityResult.getStatus().getStatusMessage()); nodes = null; } else { nodes = capabilityResult.getCapability(); } SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit(); boolean enable_wearG5 = sharedPrefs.getBoolean("enable_wearG5", false); boolean force_wearG5 = sharedPrefs.getBoolean("force_wearG5", false); String node_wearG5 = mPrefs.getString("node_wearG5", ""); if (nodes != null && nodes.getNodes().size() > 0) { updateWearSyncBgsCapability(nodes); int count = nodes.getNodes().size(); Log.d(TAG, "doInBackground connected. CapabilityApi.GetCapabilityResult mWearNodeID=" + (mWearNodeId != null ? mWearNodeId : "") + " count=" + count);//KS boolean isConnectedToWearable = false; for (Node peer : nodes.getNodes()) { //onPeerConnected String wearNode = peer.getDisplayName() + "|" + peer.getId(); Log.d(TAG, "CheckWearableConnected onPeerConnected peer name & ID: " + wearNode); if (wearNode.equals(node_wearG5)) { isConnectedToWearable = true; sendPrefSettings(); break; } else if (node_wearG5.equals("")) { isConnectedToWearable = true; prefs.putString("node_wearG5", wearNode); prefs.apply(); break; } } sendPrefSettings(); initWearData(); if (enable_wearG5) { //Only stop service if Phone will rely on Wear Collection Service if (force_wearG5 && isConnectedToWearable) { Log.d(TAG, "CheckWearableConnected onPeerConnected force_wearG5=true Phone stopBtService and continue to use Wear BT Collector"); stopBtService(); } else { Log.d(TAG, "CheckWearableConnected onPeerConnected force_wearG5=false Phone startBtService"); startBtService(); } } } else { //onPeerDisconnected Log.d(TAG, "CheckWearableConnected onPeerDisconnected"); if (sharedPrefs.getBoolean("wear_sync", false)) { Log.d(TAG, "CheckWearableConnected onPeerDisconnected wear_sync=true Phone startBtService"); startBtService(); } } } else { Log.d(TAG, "Debounce limit hit - not sending"); } } else { Log.d(TAG, "Not connected for sending"); googleApiClient.connect(); } return null; }
Example 19
Source File: WatchUpdaterService.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
@Override protected Void doInBackground(Void... voids) { if (googleApiClient.isConnected()) { if (System.currentTimeMillis() - lastRequest > 20 * 1000) { // enforce 20-second debounce period lastRequest = System.currentTimeMillis(); //NodeApi.GetConnectedNodesResult nodes = // Wearable.NodeApi.getConnectedNodes(googleApiClient).await(); if (localnode == null || (localnode != null && localnode.isEmpty())) setLocalNodeName(); CapabilityApi.GetCapabilityResult capabilityResult = Wearable.CapabilityApi.getCapability( googleApiClient, CAPABILITY_WEAR_APP, CapabilityApi.FILTER_REACHABLE).await(GET_CAPABILITIES_TIMEOUT_MS, TimeUnit.MILLISECONDS); CapabilityInfo nodes; if (!capabilityResult.getStatus().isSuccess()) { Log.e(TAG, "doInBackground Failed to get capabilities, status: " + capabilityResult.getStatus().getStatusMessage()); nodes = null; } else { nodes = capabilityResult.getCapability(); } SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit(); boolean enable_wearG5 = sharedPrefs.getBoolean("enable_wearG5", false); boolean force_wearG5 = sharedPrefs.getBoolean("force_wearG5", false); String node_wearG5 = mPrefs.getString("node_wearG5", ""); if (nodes != null && nodes.getNodes().size() > 0) { updateWearSyncBgsCapability(nodes); int count = nodes.getNodes().size(); Log.d(TAG, "doInBackground connected. CapabilityApi.GetCapabilityResult mWearNodeID=" + (mWearNodeId != null ? mWearNodeId : "") + " count=" + count);//KS boolean isConnectedToWearable = false; for (Node peer : nodes.getNodes()) { //onPeerConnected String wearNode = peer.getDisplayName() + "|" + peer.getId(); Log.d(TAG, "CheckWearableConnected onPeerConnected peer name & ID: " + wearNode); if (wearNode.equals(node_wearG5)) { isConnectedToWearable = true; sendPrefSettings(); break; } else if (node_wearG5.equals("")) { isConnectedToWearable = true; prefs.putString("node_wearG5", wearNode); prefs.apply(); break; } } sendPrefSettings(); initWearData(); if (enable_wearG5) { //Only stop service if Phone will rely on Wear Collection Service if (force_wearG5 && isConnectedToWearable) { Log.d(TAG, "CheckWearableConnected onPeerConnected force_wearG5=true Phone stopBtService and continue to use Wear BT Collector"); stopBtService(); } else { Log.d(TAG, "CheckWearableConnected onPeerConnected force_wearG5=false Phone startBtService"); startBtService(); } } } else { //onPeerDisconnected Log.d(TAG, "CheckWearableConnected onPeerDisconnected"); if (sharedPrefs.getBoolean("wear_sync", false)) { Log.d(TAG, "CheckWearableConnected onPeerDisconnected wear_sync=true Phone startBtService"); startBtService(); } } } else { Log.d(TAG, "Debounce limit hit - not sending"); } } else { Log.d(TAG, "Not connected for sending"); googleApiClient.connect(); } return null; }
Example 20
Source File: PlayNetwork.java From CrossBow with Apache License 2.0 | 4 votes |
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; }