private void checkIfPhoneHasApp() { Log.d(TAG, "checkIfPhoneHasApp()"); PendingResult<CapabilityApi.GetCapabilityResult> pendingResult = Wearable.CapabilityApi.getCapability( mGoogleApiClient, CAPABILITY_PHONE_APP, CapabilityApi.FILTER_ALL); pendingResult.setResultCallback(new ResultCallback<CapabilityApi.GetCapabilityResult>() { @Override public void onResult(@NonNull CapabilityApi.GetCapabilityResult getCapabilityResult) { Log.d(TAG, "onResult(): " + getCapabilityResult); if (getCapabilityResult.getStatus().isSuccess()) { CapabilityInfo capabilityInfo = getCapabilityResult.getCapability(); mAndroidPhoneNodeWithApp = pickBestNodeId(capabilityInfo.getNodes()); verifyNodeAndUpdateUI(); } else { Log.d(TAG, "Failed CapabilityApi: " + getCapabilityResult.getStatus()); } } }); }
private void setupF35Wearable() { CapabilityApi.GetCapabilityResult result = Wearable.CapabilityApi.getCapability( mGoogleApiClient, F35_WEARABLE_CAPABILITY_NAME, CapabilityApi.FILTER_REACHABLE).await(); updateTranscriptionCapability(result.getCapability()); //setupComplete(); we can fire messages CapabilityApi.CapabilityListener capabilityListener = new CapabilityApi.CapabilityListener() { @Override public void onCapabilityChanged(CapabilityInfo capabilityInfo) { updateTranscriptionCapability(capabilityInfo); } }; Wearable.CapabilityApi.addCapabilityListener( mGoogleApiClient, capabilityListener, F35_WEARABLE_CAPABILITY_NAME); }
@Override public void onCapabilityChanged(CapabilityInfo capabilityInfo) { Node phoneNode = updatePhoneSyncBgsCapability(capabilityInfo); Log.d(TAG, "onCapabilityChanged mPhoneNodeID:" + (phoneNode != null ? phoneNode.getId() : ""));//mPhoneNodeId //onPeerConnected and onPeerDisconnected deprecated at the same time as BIND_LISTENER if (phoneNode != null && phoneNode.getId().length() > 0) { if (JoH.ratelimit("on-connected-nodes-sync", 1200)) { Log.d(TAG, "onCapabilityChanged event - attempting resync"); requestData(); } else { Log.d(TAG, "onCapabilityChanged event - ratelimited"); } sendPrefSettings();//from onPeerConnected } }
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)); }
/** * Find the connected nodes that provide at least one of the given capabilities */ private void showNodes(final String... capabilityNames) { Task<Map<String, CapabilityInfo>> capabilitiesTask = Wearable.getCapabilityClient(this) .getAllCapabilities(CapabilityClient.FILTER_REACHABLE); capabilitiesTask.addOnSuccessListener(new OnSuccessListener<Map<String, CapabilityInfo>>() { @Override public void onSuccess(Map<String, CapabilityInfo> capabilityInfoMap) { Set<Node> nodes = new HashSet<>(); if (capabilityInfoMap.isEmpty()) { showDiscoveredNodes(nodes); return; } for (String capabilityName : capabilityNames) { CapabilityInfo capabilityInfo = capabilityInfoMap.get(capabilityName); if (capabilityInfo != null) { nodes.addAll(capabilityInfo.getNodes()); } } showDiscoveredNodes(nodes); } }); }
@Override public void onCapabilityChanged(CapabilityInfo capabilityInfo) { super.onCapabilityChanged(capabilityInfo); if (capabilityInfo.getNodes().isEmpty()) return; Log.d(TAG, "Watch connected"); forceSync(); }
@Override public void onCapabilityChanged(CapabilityInfo capabilityInfo) { Log.d(TAG, "onCapabilityChanged(): " + capabilityInfo); mAndroidPhoneNodeWithApp = pickBestNodeId(capabilityInfo.getNodes()); verifyNodeAndUpdateUI(); }
@SuppressLint("LongLogTag") @Override public void onCapabilityChanged(CapabilityInfo capabilityInfo) { Log.d(TAG, "onCapabilityChanged(): " + capabilityInfo); mWearNodesWithApp = capabilityInfo.getNodes(); // Because we have an updated list of devices with/without our app, we need to also update // our list of active Wear devices. findAllWearDevices(); verifyNodeAndUpdateUI(); }
@SuppressLint("LongLogTag") private void findWearDevicesWithApp() { Log.d(TAG, "findWearDevicesWithApp()"); // You can filter this by FILTER_REACHABLE if you only want to open Nodes (Wear Devices) // directly connect to your phone. PendingResult<CapabilityApi.GetCapabilityResult> pendingResult = Wearable.CapabilityApi.getCapability( mGoogleApiClient, CAPABILITY_WEAR_APP, CapabilityApi.FILTER_ALL); pendingResult.setResultCallback(new ResultCallback<CapabilityApi.GetCapabilityResult>() { @Override public void onResult(@NonNull CapabilityApi.GetCapabilityResult getCapabilityResult) { Log.d(TAG, "findWearDevicesWithApp onResult(): " + getCapabilityResult); if (getCapabilityResult.getStatus().isSuccess()) { CapabilityInfo capabilityInfo = getCapabilityResult.getCapability(); mWearNodesWithApp = capabilityInfo.getNodes(); verifyNodeAndUpdateUI(); } else { Log.d(TAG, "Failed CapabilityApi: " + getCapabilityResult.getStatus()); } } }); }
@Override public void onCapabilityChanged(CapabilityInfo capabilityInfo) { Set<Node> capableNodes = capabilityInfo != null ? capabilityInfo.getNodes() : null; mCapableClientDetected = capableNodes != null && capableNodes.size() > 0 ? TriStateLogicEnum.TRUE : TriStateLogicEnum.FALSE; if (mApp != null) { mApp.onCapableClientConnected(); } }
/** * Clients can register to {@link DataConsumer#onCapabilityChanged(String, Set)}. */ void onCapabilityChanged(CapabilityInfo capabilityInfo) { String capability = capabilityInfo.getName(); Set<Node> nodes = capabilityInfo.getNodes(); mCapabilityToNodesMapping.put(capability, nodes); for (DataConsumer consumer : mDataConsumers) { consumer.onCapabilityChanged(capability, nodes); } }
private void updateRemoteControlCapability(@Nullable final CapabilityInfo capabilityInfo) { if (capabilityInfo != null) { final String playbackNodeId = pickBestNodeId(capabilityInfo.getNodes()); mPlaybackNodeListener.onNodeConnectionStateChanged(playbackNodeId != null); synchronized (mCapabilityLock) { mPlaybackControlNodeId = playbackNodeId; } } }
private void findCapableNode(final String capability) { Log.d(TAG,"Start looking for a capable node"); new Thread(new Runnable() { @Override public void run() { CapabilityApi.GetCapabilityResult result = Wearable.CapabilityApi.getCapability(googleApiClient,capability,CapabilityApi.FILTER_REACHABLE).await(); CapabilityInfo capabilityInfo = result.getCapability(); Set<Node> nodes = capabilityInfo.getNodes(); String nodeID = findBestNodeId(nodes); Log.d(TAG,"Node found: "+nodeID); if (nodeID==null) { //This might be caused by there not being a watch paired to the device //Run it on the UI thread ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { errorListener.onError(new Throwable("Error, cannot find a connected device")); } }); return; } WearSocket.this.nodeID = nodeID; nodeFound.release(); } }).start(); }
private void loadNodes() { Task<CapabilityInfo> capabilityTask = Wearable.getCapabilityClient(this) .getCapability(CORDOVA_CAPABILITY, CapabilityClient.FILTER_REACHABLE); capabilityTask.addOnSuccessListener(new OnSuccessListener<CapabilityInfo>() { @Override public void onSuccess(CapabilityInfo capabilityInfo) { WearProviderService.this.onCapabilityChanged(capabilityInfo); } }); }
public <T> T sendMessageAndReceive(Object msg, int operationTimeout, Class<T> clazz) throws IOException { makeSureIsConnected(); CapabilityInfo capabilityInfo = Wearable.CapabilityApi.getCapability( googleClient, context.getString(R.string.jj_request_proxy), CapabilityApi.FILTER_REACHABLE).await().getCapability(); if (capabilityInfo == null) { throw new ConnectionException("CapabilityApi unavailable"); } Set<Node> nodes = capabilityInfo.getNodes(); String id = generateUniqId(); Object waitObject = new Object(); waitObjects.put(id, waitObject); sendMessage(id, pickBestNodeId(nodes), msg); try { synchronized (waitObject) { waitObject.wait(readTimeout + operationTimeout); } } catch (InterruptedException e) { throw new ConnectionException("GoogleApiClient timeout"); } finally { waitObjects.remove(id); } byte[] message = resultObjects.remove(id); if (message != null) { return readObject(message, clazz); } else { throw new ConnectionException("GoogleApiClient timeout"); } }
private void updateTranscriptionCapability(CapabilityInfo capabilityInfo) { Set<Node> connectedNodes = capabilityInfo.getNodes(); transcriptionNodeId = pickBestNodeId(connectedNodes); }
private void updateTranscriptionCapability(CapabilityInfo capabilityInfo) { Set<Node> connectedNodes = capabilityInfo.getNodes(); phoneNodeId = pickBestNodeId(connectedNodes); }
private Node updatePhoneSyncBgsCapability(CapabilityInfo capabilityInfo) { Set<Node> connectedNodes = capabilityInfo.getNodes(); return pickBestNode(connectedNodes); //mPhoneNodeId = pickBestNodeId(connectedNodes); }
private void updateWearSyncBgsCapability(CapabilityInfo capabilityInfo) { Set<Node> connectedNodes = capabilityInfo.getNodes(); mWearNodeId = pickBestNodeId(connectedNodes); }
@Override public void onCapabilityChanged(CapabilityInfo capabilityInfo) { updateWearSyncBgsCapability(capabilityInfo); Log.d(TAG, "onConnected onCapabilityChanged mWearNodeID:" + mWearNodeId); new CheckWearableConnected().execute(); }
@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.commit(); 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; }
private void updateTranscriptionCapability(CapabilityInfo capabilityInfo) { Set<Node> connectedNodes = capabilityInfo.getNodes(); hostNodeId = pickBestNodeId(connectedNodes); }
/** * Clients can register to {@link DataConsumer#onGmsApiConnected()}. */ private void onConnected(Bundle bundle) { WearUtil.logD(TAG, "Google Api Connected"); for (DataConsumer consumer : mDataConsumers) { consumer.onGmsApiConnected(); } addCapabilities(mCapabilitiesToBeAdded); Wearable.CapabilityApi.getAllCapabilities(mGoogleApiClient, CapabilityApi.FILTER_REACHABLE).setResultCallback( new ResultCallback<CapabilityApi.GetAllCapabilitiesResult>() { @Override public void onResult( CapabilityApi.GetAllCapabilitiesResult getAllCapabilitiesResult) { if (getAllCapabilitiesResult.getStatus().isSuccess()) { Map<String, CapabilityInfo> capabilities = getAllCapabilitiesResult .getAllCapabilities(); if (capabilities != null) { for (String capability : capabilities.keySet()) { CapabilityInfo info = capabilities.get(capability); mCapabilityToNodesMapping.put(capability, info.getNodes()); } } onConnectedInitialCapabilitiesReceived(); } else { Log.e(TAG, "getAllCapabilities(): Failed to get all the capabilities"); } } }); Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).setResultCallback( new ResultCallback<NodeApi.GetConnectedNodesResult>() { @Override public void onResult(NodeApi.GetConnectedNodesResult getConnectedNodesResult) { if (getConnectedNodesResult.getStatus().isSuccess()) { mConnectedNodes.clear(); mConnectedNodes.addAll(getConnectedNodesResult.getNodes()); onConnectedInitialNodesReceived(); } } }); }
@Override public void onCapabilityChanged(CapabilityInfo capabilityInfo) { super.onCapabilityChanged(capabilityInfo); mGmsWear.onCapabilityChanged(capabilityInfo); }
private void onActionSearch(@NonNull final Intent intent) { final String query = intent.getStringExtra(EXTRA_QUERY); if (query == null) { throw new IllegalArgumentException("EXTRA_QUERY is null"); } final WearSearchData.Results results = new WearSearchData.Results(); results.albums = queryAlbums(query); results.artists = queryArtists(query); results.tracks = queryTracks(query); final GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API).build(); final ConnectionResult connectionResult = googleApiClient.blockingConnect(); if (!connectionResult.isSuccess()) { Log.w(TAG, "GoogleApiClient not connected: " + GoogleApiAvailability.getInstance() .getErrorString(connectionResult.getErrorCode())); return; } try { final String capability = getString(R.string.wear_capability_search_receiver); final CapabilityApi.GetCapabilityResult capabilityResult = Wearable.CapabilityApi .getCapability(googleApiClient, capability, CapabilityApi.FILTER_REACHABLE) .await(); final CapabilityInfo capabilityInfo = capabilityResult.getCapability(); if (capabilityInfo == null) { Log.w(TAG, "No search receiver devices connected"); return; } final String searchReceiverNodeId = pickBestNodeId(capabilityInfo.getNodes()); if (TextUtils.isEmpty(searchReceiverNodeId)) { Log.w(TAG, "No search receiver nodes found"); return; } final byte[] resultsArray; try { resultsArray = ProtoUtils.toByteArray(results); } catch (IOException e) { Log.w(TAG, e); return; } Wearable.MessageApi.sendMessage(googleApiClient, searchReceiverNodeId, DataPaths.Messages.SEARCH_RESULT, resultsArray).await(); } finally { googleApiClient.disconnect(); } }
@Override public void onCapabilityChanged(CapabilityInfo capabilityInfo) { super.onCapabilityChanged(capabilityInfo); Log.d(TAG, "onCapabilityChanged() ...") ; }
private void updateReceiverActionTriggerCapability(CapabilityInfo capabilityInfo) { connectedNodes = capabilityInfo.getNodes(); }
@Override public void onCapabilityChanged(CapabilityInfo capabilityInfo) { DataManager.getInstance(this).updateCapability(capabilityInfo); }
public void updateCapability(CapabilityInfo capabilityInfo) { // TODO: Do something with this capabilityinfo. }
@Override public void onCapabilityChanged(@NonNull CapabilityInfo capabilityInfo) { LOGD(TAG, "onCapabilityChanged: " + capabilityInfo); syncNodes(capabilityInfo.getNodes()); }
@Override public void onCapabilityChanged(CapabilityInfo capabilityInfo) { LOGD(TAG, "onCapabilityChanged: " + capabilityInfo); mDataFragment.appendItem("onCapabilityChanged", capabilityInfo.toString()); }
@Override public void onCapabilityChanged(final CapabilityInfo capabilityInfo) { LOGD(TAG, "onCapabilityChanged: " + capabilityInfo); mDataItemListAdapter.add(new Event("onCapabilityChanged", capabilityInfo.toString())); }
@Override @CallSuper public void onCapabilityChanged(CapabilityInfo capabilityInfo) { }