com.google.android.gms.wearable.CapabilityApi Java Examples

The following examples show how to use com.google.android.gms.wearable.CapabilityApi. 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 vote down vote up
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 vote down vote up
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: ListenerService.java    From AndroidAPS with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onConnected(Bundle bundle) {
    // Log.d(TAG, logPrefix + "onConnected call requestData");

    CapabilityApi.CapabilityListener capabilityListener = new CapabilityApi.CapabilityListener() {

        @Override
        public void onCapabilityChanged(CapabilityInfo capabilityInfo) {
            updatePhoneSyncBgsCapability(capabilityInfo);
            Log.d(TAG, logPrefix + "onConnected onCapabilityChanged mPhoneNodeID:" + mPhoneNodeId
                + ", Capability: " + capabilityInfo);
        }
    };

    Wearable.CapabilityApi.addCapabilityListener(googleApiClient, capabilityListener, CAPABILITY_PHONE_APP);

    Wearable.ChannelApi.addListener(googleApiClient, this);
    requestData();
}
 
Example #4
Source File: MessageApiHandler.java    From PowerSwitch_Android with GNU General Public License v3.0 6 votes vote down vote up
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 #5
Source File: DisconnectListenerService.java    From android-FindMyPhone with Apache License 2.0 6 votes vote down vote up
private void setOrUpdateNotification() {
    Wearable.CapabilityApi.getCapability(
            mGoogleApiClient, FIND_ME_CAPABILITY_NAME,
            CapabilityApi.FILTER_REACHABLE).setResultCallback(
            new ResultCallback<CapabilityApi.GetCapabilityResult>() {
                @Override
                public void onResult(CapabilityApi.GetCapabilityResult result) {
                    if (result.getStatus().isSuccess()) {
                        updateFindMeCapability(result.getCapability());
                    } else {
                        Log.e(TAG,
                                "setOrUpdateNotification() Failed to get capabilities, "
                                        + "status: "
                                        + result.getStatus().getStatusMessage());
                    }
                }
            });
}
 
Example #6
Source File: QuizReportActionService.java    From android-Quiz with Apache License 2.0 6 votes vote down vote up
@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 #7
Source File: ActivityMain.java    From CrossBow with Apache License 2.0 6 votes vote down vote up
private void getBestNode(long timeOut){
    final String nodeCompatibilty = getString(com.crossbow.wear.R.string.crossbow_compatibility);
    Wearable.CapabilityApi.getCapability(googleApiClient, nodeCompatibilty, CapabilityApi.FILTER_REACHABLE).setResultCallback(
        new ResultCallback<CapabilityApi.GetCapabilityResult>() {
            @Override
            public void onResult(CapabilityApi.GetCapabilityResult nodes) {
            String nodeID = null;
            Set<Node> nodeList = nodes.getCapability().getNodes();

            //get the nearest node
            for(Node node : nodeList) {
                if(node.isNearby()) {
                    nodeID = node.getId();
                    break;
                }
                nodeID = node.getId();
            }
            sendMessage(nodeID);
                }
            }
    );

}
 
Example #8
Source File: UtilityService.java    From wear-os-samples with Apache License 2.0 5 votes vote down vote up
/**
 * 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: ListenerService.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
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 #10
Source File: WatchUpdaterService.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onConnected(Bundle connectionHint) {
    CapabilityApi.CapabilityListener capabilityListener = capabilityInfo -> {
        updateWearSyncBgsCapability(capabilityInfo);
        // Log.d(TAG, logPrefix + "onConnected onCapabilityChanged mWearNodeID:" + mWearNodeId);
        // new CheckWearableConnected().execute();
    };

    Wearable.CapabilityApi.addCapabilityListener(googleApiClient, capabilityListener, CAPABILITY_WEAR_APP);
    sendData();
}
 
Example #11
Source File: UtilityService.java    From io2015-codelabs with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #12
Source File: UtilityService.java    From io2015-codelabs with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #13
Source File: WatchUpdaterService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
@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 #14
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
@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 #15
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;
}