Java Code Examples for com.google.android.gms.wearable.CapabilityApi#GetCapabilityResult
The following examples show how to use
com.google.android.gms.wearable.CapabilityApi#GetCapabilityResult .
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: WatchUpdaterService.java From xDrip with GNU General Public License v3.0 | 6 votes |
private void updateWearSyncBgsCapability() { 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, "updateWearSyncBgsCapability Failed to get capabilities, status: " + capabilityResult.getStatus().getStatusMessage()); nodes = null; } else { nodes = capabilityResult.getCapability(); } if (nodes != null && nodes.getNodes().size() > 0) { Log.d(TAG, "Updating wear sync nodes"); updateWearSyncBgsCapability(nodes); } }
Example 2
Source File: WatchUpdaterService.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
private void updateWearSyncBgsCapability() { 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, "updateWearSyncBgsCapability Failed to get capabilities, status: " + capabilityResult.getStatus().getStatusMessage()); nodes = null; } else { nodes = capabilityResult.getCapability(); } if (nodes != null && nodes.getNodes().size() > 0) { Log.d(TAG, "Updating wear sync nodes"); updateWearSyncBgsCapability(nodes); } }
Example 3
Source File: MessageApiHandler.java From PowerSwitch_Android with GNU General Public License v3.0 | 6 votes |
private void setupReachableReceiverActionTrigger() { CapabilityApi.GetCapabilityResult result = Wearable.CapabilityApi.getCapability( googleApiClient, context .getResources() .getString(eu.power_switch.shared.R.string.RECEIVER_ACTION_TRIGGER_CAPABILITY_NAME), CapabilityApi.FILTER_REACHABLE) .await(); updateReceiverActionTriggerCapability(result.getCapability()); CapabilityApi.CapabilityListener capabilityListener = new CapabilityApi.CapabilityListener() { @Override public void onCapabilityChanged(CapabilityInfo capabilityInfo) { updateReceiverActionTriggerCapability(capabilityInfo); } }; Wearable.CapabilityApi.addCapabilityListener(googleApiClient, capabilityListener, context.getResources() .getString(eu.power_switch.shared.R.string.RECEIVER_ACTION_TRIGGER_CAPABILITY_NAME)); }
Example 4
Source File: QuizReportActionService.java From android-Quiz with Apache License 2.0 | 6 votes |
@Override public void onHandleIntent(Intent intent) { if (intent.getAction().equals(ACTION_RESET_QUIZ)) { final GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .build(); ConnectionResult result = googleApiClient.blockingConnect(CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS); if (!result.isSuccess()) { Log.e(TAG, "QuizReportActionService failed to connect to GoogleApiClient."); return; } CapabilityApi.GetCapabilityResult capabilityResult = Wearable.CapabilityApi .getCapability(googleApiClient, RESET_QUIZ_CAPABILITY_NAME, CapabilityApi.FILTER_REACHABLE) .await(GET_CAPABILITIES_TIMEOUT_MS, TimeUnit.MILLISECONDS); if (capabilityResult.getStatus().isSuccess()) { sendResetMessage(googleApiClient, capabilityResult.getCapability()); } else { Log.e(TAG, "Failed to get capabilities, status: " + capabilityResult.getStatus().getStatusMessage()); } } }
Example 5
Source File: UtilityService.java From wear-os-samples with Apache License 2.0 | 5 votes |
/** * Sends the actual message to ask other devices that are capable of showing "details" to start * the appropriate activity * * @param path the path to pass to the wearable message API * @param extraInfo extra info that varies based on the path being sent */ private void startDeviceActivityInternal(String path, String extraInfo) { GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .build(); ConnectionResult connectionResult = googleApiClient.blockingConnect( Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS); if (connectionResult.isSuccess() && googleApiClient.isConnected()) { CapabilityApi.GetCapabilityResult result = Wearable.CapabilityApi.getCapability( googleApiClient, getApplicationContext().getString(R.string.show_detail_capability_name), CapabilityApi.FILTER_REACHABLE) .await(GET_CAPABILITY_TIMEOUT_S, TimeUnit.SECONDS); if (result.getStatus().isSuccess()) { Set<Node> nodes = result.getCapability().getNodes(); for (Node node : nodes) { Wearable.MessageApi.sendMessage( googleApiClient, node.getId(), path, extraInfo.getBytes()); } } else { Log.e(TAG, "startDeviceActivityInternal() Failed to get capabilities, status: " + result.getStatus().getStatusMessage()); } googleApiClient.disconnect(); } }
Example 6
Source File: ListenerService.java From AndroidAPS with GNU Affero General Public License v3.0 | 5 votes |
public CapabilityInfo getCapabilities() { CapabilityApi.GetCapabilityResult capabilityResult = Wearable.CapabilityApi.getCapability(googleApiClient, CAPABILITY_PHONE_APP, CapabilityApi.FILTER_REACHABLE).await(GET_CAPABILITIES_TIMEOUT_MS, TimeUnit.MILLISECONDS); if (!capabilityResult.getStatus().isSuccess()) { Log.e(TAG, logPrefix + "doInBackground Failed to get capabilities, status: " + capabilityResult.getStatus().getStatusMessage()); return null; } return capabilityResult.getCapability(); }
Example 7
Source File: UtilityService.java From io2015-codelabs with Apache License 2.0 | 5 votes |
/** * Sends the actual message to ask other devices that are capable of showing "details" to start * the appropriate activity * * @param path the path to pass to the wearable message API * @param extraInfo extra info that varies based on the path being sent */ private void startDeviceActivityInternal(String path, String extraInfo) { GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .build(); ConnectionResult connectionResult = googleApiClient.blockingConnect( Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS); if (connectionResult.isSuccess() && googleApiClient.isConnected()) { CapabilityApi.GetCapabilityResult result = Wearable.CapabilityApi.getCapability( googleApiClient, getApplicationContext().getString(R.string.show_detail_capability_name), CapabilityApi.FILTER_REACHABLE) .await(GET_CAPABILITY_TIMEOUT_S, TimeUnit.SECONDS); if (result.getStatus().isSuccess()) { Set<Node> nodes = result.getCapability().getNodes(); for (Node node : nodes) { Wearable.MessageApi.sendMessage( googleApiClient, node.getId(), path, extraInfo.getBytes()); } } else { Log.e(TAG, "startDeviceActivityInternal() Failed to get capabilities, status: " + result.getStatus().getStatusMessage()); } googleApiClient.disconnect(); } }
Example 8
Source File: UtilityService.java From io2015-codelabs with Apache License 2.0 | 5 votes |
/** * Sends the actual message to ask other devices that are capable of showing "details" to start * the appropriate activity * * @param path the path to pass to the wearable message API * @param extraInfo extra info that varies based on the path being sent */ private void startDeviceActivityInternal(String path, String extraInfo) { GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .build(); ConnectionResult connectionResult = googleApiClient.blockingConnect( Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS); if (connectionResult.isSuccess() && googleApiClient.isConnected()) { CapabilityApi.GetCapabilityResult result = Wearable.CapabilityApi.getCapability( googleApiClient, getApplicationContext().getString(R.string.show_detail_capability_name), CapabilityApi.FILTER_REACHABLE) .await(GET_CAPABILITY_TIMEOUT_S, TimeUnit.SECONDS); if (result.getStatus().isSuccess()) { Set<Node> nodes = result.getCapability().getNodes(); for (Node node : nodes) { Wearable.MessageApi.sendMessage( googleApiClient, node.getId(), path, extraInfo.getBytes()); } } else { Log.e(TAG, "startDeviceActivityInternal() Failed to get capabilities, status: " + result.getStatus().getStatusMessage()); } googleApiClient.disconnect(); } }
Example 9
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 10
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 11
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; }