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

The following examples show how to use com.google.android.gms.wearable.NodeApi. 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: UARTCommandsActivity.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Sends the given command to the handheld.
 *
 * @param command the message
 */
private void sendMessageToHandheld(final @NonNull Context context, final @NonNull String command) {
	new Thread(() -> {
		final GoogleApiClient client = new GoogleApiClient.Builder(context)
				.addApi(Wearable.API)
				.build();
		client.blockingConnect();

		final NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(client).await();
		for (Node node : nodes.getNodes()) {
			final MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(client, node.getId(), Constants.UART.COMMAND, command.getBytes()).await();
			if (!result.getStatus().isSuccess()) {
				Log.w(TAG, "Failed to send " + Constants.UART.COMMAND + " to " + node.getDisplayName());
			}
		}
		client.disconnect();
	}).start();
}
 
Example #2
Source File: WearableApi.java    From LibreAlarm with GNU General Public License v3.0 6 votes vote down vote up
public static void sendMessage(final GoogleApiClient client, final String command,
        final byte[] message, final ResultCallback<MessageApi.SendMessageResult> listener) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            NodeApi.GetConnectedNodesResult nodes =
                    Wearable.NodeApi.getConnectedNodes( client ).await();
            for(Node node : nodes.getNodes()) {
                Log.i(TAG, "sending to " + node.getId() + ", command: " + command);
                PendingResult<MessageApi.SendMessageResult> pR =
                        Wearable.MessageApi.sendMessage(client, node.getId(), command, message);
                if (listener != null) pR.setResultCallback(listener);
            }
        }
    }).start();
}
 
Example #3
Source File: RemoteSensorManager.java    From SensorDashboard with Apache License 2.0 6 votes vote down vote up
private void controlMeasurementInBackground(final String path) {
    if (validateConnection()) {
        List<Node> nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await().getNodes();

        Log.d(TAG, "Sending to nodes: " + nodes.size());

        for (Node node : nodes) {
            Log.i(TAG, "add node " + node.getDisplayName());
            Wearable.MessageApi.sendMessage(
                    googleApiClient, node.getId(), path, null
            ).setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
                @Override
                public void onResult(MessageApi.SendMessageResult sendMessageResult) {
                    Log.d(TAG, "controlMeasurementInBackground(" + path + "): " + sendMessageResult.getStatus().isSuccess());
                }
            });
        }
    } else {
        Log.w(TAG, "No connection possible");
    }
}
 
Example #4
Source File: ListenerService.java    From NightWatch with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Void doInBackground(Void... params) {
    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();
            for (Node node : nodes.getNodes()) {
                Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), WEARABLE_RESEND_PATH, null);
            }
        }
    } else
        googleApiClient.connect();
    return null;
}
 
Example #5
Source File: GoogleApiMessenger.java    From Sensor-Data-Logger with Apache License 2.0 6 votes vote down vote up
public void sendMessageToNearbyNodes(final String path, final byte[] data) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            NodeApi.GetConnectedNodesResult getConnectedNodesResult = Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
            status.setLastConnectedNodes(getConnectedNodesResult.getNodes());
            status.setLastConnectedNodesUpdateTimestamp(System.currentTimeMillis());
            for (Node node : status.getLastConnectedNodes()) {
                try {
                    if (!node.isNearby()) {
                        continue;
                    }
                    sendMessageToNodeWithResult(path, data, node.getId());
                } catch (Exception ex) {
                    Log.w(TAG, "Unable to send message to node: " + ex.getMessage());
                }
            }
        }
    }).start();
}
 
Example #6
Source File: SendToDataLayerThread.java    From NightWatch with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Void doInBackground(DataMap... params) {
    NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
    for (Node node : nodes.getNodes()) {
        for (DataMap dataMap : params) {
            PutDataMapRequest putDMR = PutDataMapRequest.create(path);
            putDMR.getDataMap().putAll(dataMap);
            PutDataRequest request = putDMR.asPutDataRequest();
            DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleApiClient,request).await();
            if (result.getStatus().isSuccess()) {
                Log.d("SendDataThread", "DataMap: " + dataMap + " sent to: " + node.getDisplayName());
            } else {
                Log.d("SendDataThread", "ERROR: failed to send DataMap");
            }
        }
    }

    return null;
}
 
Example #7
Source File: MainActivity.java    From DronesWear with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onConnected(Bundle bundle) {
    Wearable.DataApi.addListener(mGoogleApiClient, this);

    if (mDrone != null) {
        Message.sendActionTypeMessage(mDrone.getCurrentAction(), mGoogleApiClient);
    }
    sendInteractionType();

    // launch the app on the wear
    Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).setResultCallback(
            new ResultCallback<NodeApi.GetConnectedNodesResult>() {
        @Override
        public void onResult(@NonNull NodeApi.GetConnectedNodesResult getConnectedNodesResult) {
            for (Node node : getConnectedNodesResult.getNodes()) {
                Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(),
                        Message.OPEN_ACTIVITY_MESSAGE, new byte[0]);
            }
        }
    });
}
 
Example #8
Source File: MainActivity.java    From android-Quiz with Apache License 2.0 6 votes vote down vote up
private void sendMessageToWearable(final String path, final byte[] data) {
    Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).setResultCallback(
            new ResultCallback<NodeApi.GetConnectedNodesResult>() {
                @Override
                public void onResult(NodeApi.GetConnectedNodesResult nodes) {
                    for (Node node : nodes.getNodes()) {
                        Wearable.MessageApi
                                .sendMessage(mGoogleApiClient, node.getId(), path, data);
                    }

                    if (path.equals(QUIZ_EXITED_PATH) && mGoogleApiClient.isConnected()) {
                        mGoogleApiClient.disconnect();
                    }
                }
            });
}
 
Example #9
Source File: ListenerService.java    From AndroidAPS with GNU Affero General Public License v3.0 6 votes vote down vote up
private void setLocalNodeName() {
    forceGoogleApiConnect();
    PendingResult<NodeApi.GetLocalNodeResult> result = Wearable.NodeApi.getLocalNode(googleApiClient);
    result.setResultCallback(new ResultCallback<NodeApi.GetLocalNodeResult>() {

        @Override
        public void onResult(NodeApi.GetLocalNodeResult getLocalNodeResult) {
            if (!getLocalNodeResult.getStatus().isSuccess()) {
                Log.e(TAG, "ERROR: failed to getLocalNode Status="
                    + getLocalNodeResult.getStatus().getStatusMessage());
            } else {
                Log.d(TAG, "getLocalNode Status=: " + getLocalNodeResult.getStatus().getStatusMessage());
                Node getnode = getLocalNodeResult.getNode();
                localnode = getnode != null ? getnode.getDisplayName() + "|" + getnode.getId() : "";
                Log.d(TAG, "setLocalNodeName.  localnode=" + localnode);
            }
        }
    });
}
 
Example #10
Source File: ListenerService.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Void doInBackground(Void... params) {
    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();
            for (Node node : nodes.getNodes()) {
                Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), WEARABLE_RESEND_PATH, null);
            }
        }
    } else
        googleApiClient.connect();
    return null;
}
 
Example #11
Source File: SendToDataLayerThread.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Void doInBackground(DataMap... params) {
    try {
        final NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(15, TimeUnit.SECONDS);
        for (Node node : nodes.getNodes()) {
            for (DataMap dataMap : params) {
                PutDataMapRequest putDMR = PutDataMapRequest.create(path);
                putDMR.getDataMap().putAll(dataMap);
                PutDataRequest request = putDMR.asPutDataRequest();
                DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleApiClient, request).await(15, TimeUnit.SECONDS);
                if (result.getStatus().isSuccess()) {
                    Log.d(TAG, "DataMap: " + dataMap + " sent to: " + node.getDisplayName());
                } else {
                    Log.d(TAG, "ERROR: failed to send DataMap");
                }
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Got exception sending data to wear: " + e.toString());
    }
    return null;
}
 
Example #12
Source File: WatchSyncService.java    From earth with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onConnected(@Nullable Bundle bundle) {
    Log.d(TAG, "connected to Google API Client");

    Wearable.NodeApi.addListener(client, this);

    Wearable.NodeApi.getConnectedNodes(client).setResultCallback(result -> {
        int count = connected.addAndGet(result.getNodes().size());
        if (count == 0) {
            Log.d(TAG, "no watch connected, stopping...");
            stopSelf();
        } else {
            Log.d(TAG, "connected watch: " + count);
            sendOnWatchConnected();
        }
    });
}
 
Example #13
Source File: BroadcastService.java    From sensordatacollector with GNU General Public License v2.0 6 votes vote down vote up
public void sendMessage(final String path, final byte[] bytes)
{
    new Thread(new Runnable()
    {
        @Override
        public void run()
        {
            NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(gac).await();
            while(nodes.getNodes().size() == 0) {
                Utils.sleep(500);
                nodes = Wearable.NodeApi.getConnectedNodes(gac).await();
            }

            for(Node node : nodes.getNodes()) {
                Wearable.MessageApi.sendMessage(gac, node.getId(), path, bytes).await();
            }
        }
    }).start();
}
 
Example #14
Source File: BroadcastService.java    From sensordatacollector with GNU General Public License v2.0 6 votes vote down vote up
public void sendMessage(final String path, final String text)
{
    new Thread(new Runnable()
    {
        @Override
        public void run()
        {
            NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(gac).await();
            while(nodes.getNodes().size() == 0) {
                Utils.sleep(500);
                nodes = Wearable.NodeApi.getConnectedNodes(gac).await();
            }

            for(Node node : nodes.getNodes()) {
                Wearable.MessageApi.sendMessage(gac, node.getId(), path, text.getBytes()).await();
            }
        }
    }).start();
}
 
Example #15
Source File: MainActivity.java    From WearOngoingNotificationSample with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void dismissNotification() {
    if (mGoogleApiClient.isConnected()) {
        new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(Void... params) {
                NodeApi.GetConnectedNodesResult nodes =
                        Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
                for (Node node : nodes.getNodes()) {
                    MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(
                            mGoogleApiClient, node.getId(), Constants.PATH_DISMISS, null).await();
                    if (!result.getStatus().isSuccess()) {
                        Log.e(TAG, "ERROR: failed to send Message: " + result.getStatus());
                    }
                }

                return null;
            }
        }.execute();
    }
}
 
Example #16
Source File: DigitalWatchFaceUtil.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Asynchronously fetches the current config {@link DataMap} for {@link DigitalWatchFaceService}
 * and passes it to the given callback.
 * <p>
 * If the current config {@link DataItem} doesn't exist, it isn't created and the callback
 * receives an empty DataMap.
 */
public static void fetchConfigDataMap(final GoogleApiClient client,
        final FetchConfigDataMapCallback callback) {
    Wearable.NodeApi.getLocalNode(client).setResultCallback(
            new ResultCallback<NodeApi.GetLocalNodeResult>() {
                @Override
                public void onResult(NodeApi.GetLocalNodeResult getLocalNodeResult) {
                    String localNode = getLocalNodeResult.getNode().getId();
                    Uri uri = new Uri.Builder()
                            .scheme("wear")
                            .path(DigitalWatchFaceUtil.PATH_WITH_FEATURE)
                            .authority(localNode)
                            .build();
                    Wearable.DataApi.getDataItem(client, uri)
                            .setResultCallback(new DataItemResultCallback(callback));
                }
            }
    );
}
 
Example #17
Source File: ListenerService.java    From NightWatch with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Void doInBackground(Void... params) {
    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();
            for (Node node : nodes.getNodes()) {
                Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), WEARABLE_RESEND_PATH, null);
            }
        }
    } else
        googleApiClient.connect();
    return null;
}
 
Example #18
Source File: SendToDataLayerThread.java    From NightWatch with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Void doInBackground(DataMap... params) {
    NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
    for (Node node : nodes.getNodes()) {
        for (DataMap dataMap : params) {
            PutDataMapRequest putDMR = PutDataMapRequest.create(path);
            putDMR.getDataMap().putAll(dataMap);
            PutDataRequest request = putDMR.asPutDataRequest();
            DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleApiClient,request).await();
            if (result.getStatus().isSuccess()) {
                Log.d("SendDataThread", "DataMap: " + dataMap + " sent to: " + node.getDisplayName());
            } else {
                Log.d("SendDataThread", "ERROR: failed to send DataMap");
            }
        }
    }

    return null;
}
 
Example #19
Source File: ProjectBaseActivity.java    From sms-ticket with Apache License 2.0 6 votes vote down vote up
@Override
protected void onStart() {
    super.onStart();
    mTeleportClient.connect();
    Wearable.NodeApi.getConnectedNodes(mTeleportClient.getGoogleApiClient()).setResultCallback(new ResultCallback<NodeApi
        .GetConnectedNodesResult>() {


        @Override
        public void onResult(NodeApi.GetConnectedNodesResult getConnectedNodesResult) {
            if (getConnectedNodesResult.getNodes().size() > 0) {
                startConnected();
            } else {
                startDisconnected();
            }
        }
    });
}
 
Example #20
Source File: Emmet.java    From Wear-Emmet with Apache License 2.0 6 votes vote down vote up
protected void sendMessage(final String path, final String message) {
    if (mApiClient != null) {
        if (mApiClient.isConnected()) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    final NodeApi.GetConnectedNodesResult nodes =
                            Wearable.NodeApi.getConnectedNodes(mApiClient).await();
                    for (Node node : nodes.getNodes()) {
                        MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(
                                mApiClient, node.getId(), path, message.getBytes()).await();

                    }
                }
            }).start();
        } else {
            mWaitingMessageItems.add(new Pair<>(path, message));
            mApiClient.connect();
        }
    }
}
 
Example #21
Source File: SunsetsWatchFaceUtil.java    From american-sunsets-watch-face with Apache License 2.0 6 votes vote down vote up
public static void fetchConfigDataMap(final GoogleApiClient client,
                                      final FetchConfigDataMapCallback callback) {
    Wearable.NodeApi.getLocalNode(client).setResultCallback(
            new ResultCallback<NodeApi.GetLocalNodeResult>() {
                @Override
                public void onResult(NodeApi.GetLocalNodeResult getLocalNodeResult) {
                    String localNode = getLocalNodeResult.getNode().getId();
                    Uri uri = new Uri.Builder()
                            .scheme("wear")
                            .path(SunsetsWatchFaceUtil.PATH_WITH_FEATURE)
                            .authority(localNode)
                            .build();
                    Wearable.DataApi.getDataItem(client, uri)
                            .setResultCallback(new DataItemResultCallback(callback));
                }
            }
    );
}
 
Example #22
Source File: Courier.java    From courier with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves and returns a Node representing this device. This must not be called
 * on the main thread.
 *
 * @param context The Context used to connect to the wearable API.
 * @return a Node representing this device, or null if the Wearable API is unavailable.
 */
@Nullable public static Node getLocalNode(final Context context) {
    if(Looper.myLooper()==Looper.getMainLooper()) {
        throw new IllegalStateException("getLocalNode can not be called from the UI thread");
    }

    if(WearableApis.hasMockNodeApi()) {
        return WearableApis.NodeApi.getLocalNode(null).await().getNode();
    }

    WearableApis.ensureApiClient(context);
    if (WearableApis.googleApiClient != null) {
        return WearableApis.NodeApi.getLocalNode(WearableApis.googleApiClient).await().getNode();
    } else {
        return null;
    }
}
 
Example #23
Source File: SunsetsWatchFaceUtil.java    From american-sunsets-watch-face with Apache License 2.0 6 votes vote down vote up
/**
 * Asynchronously fetches the current config {@link DataMap} for {@link SunsetsWatchFace}
 * and passes it to the given callback.
 * <p>
 * If the current config {@link DataItem} doesn't exist, it isn't created and the callback
 * receives an empty DataMap.
 */
public static void fetchConfigDataMap(final GoogleApiClient client,
                                      final FetchConfigDataMapCallback callback) {
    Wearable.NodeApi.getLocalNode(client).setResultCallback(
            new ResultCallback<NodeApi.GetLocalNodeResult>() {
                @Override
                public void onResult(NodeApi.GetLocalNodeResult getLocalNodeResult) {
                    String localNode = getLocalNodeResult.getNode().getId();
                    Uri uri = new Uri.Builder()
                            .scheme("wear")
                            .path(SunsetsWatchFaceUtil.PATH_WITH_FEATURE)
                            .authority(localNode)
                            .build();
                    Wearable.DataApi.getDataItem(client, uri)
                            .setResultCallback(new DataItemResultCallback(callback));
                }
            }
    );
}
 
Example #24
Source File: MainActivity.java    From arcgis-runtime-demos-android with Apache License 2.0 6 votes vote down vote up
private void sendEvent(final byte[] message) {
  if (mGoogleApiClient.isConnected()) {
    new Thread(new Runnable() {
      @Override
      public void run() {
        NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
        for (Node node : nodes.getNodes()) {
          MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), MESSAGE_PATH, message).await();
          if (!result.getStatus().isSuccess()) {
            Log.e("test", "error");
          } else {
            Log.i("test", "success!! sent to: " + node.getDisplayName());
          }
        }
      }
    }).start();
  } else {
    Log.e("test", "google api not connected");
  }
}
 
Example #25
Source File: CommunicationService.java    From rnd-android-wear-tesla with MIT License 6 votes vote down vote up
private void retrieveHandHoldDeviceNode() {
    new Thread(new Runnable() {
        @Override
        public void run() {
            if (mGoogleApiClient != null && !(mGoogleApiClient.isConnected() || mGoogleApiClient.isConnecting()))
                mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS);

            NodeApi.GetConnectedNodesResult result =
                    Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();

            List<Node> nodes = result.getNodes();

            if (nodes.size() > 0)
                mNodeId = nodes.get(0).getId();

            Log.v(LOG_TAG, "Node ID of phone: " + mNodeId);

            mGoogleApiClient.disconnect();
        }
    }).start();
}
 
Example #26
Source File: MainActivity.java    From rnd-android-wear-tesla with MIT License 6 votes vote down vote up
private void retrieveWearableDeviceNode() {
    new Thread(new Runnable() {
        @Override
        public void run() {
            if (mGoogleApiClient != null && !(mGoogleApiClient.isConnected() || mGoogleApiClient.isConnecting()))
                mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS);

            NodeApi.GetConnectedNodesResult result =
                    Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();

            List<Node> nodes = result.getNodes();

            if (nodes.size() > 0)
                mNodeId = nodes.get(0).getId();

            Log.v(TAG, "Node ID of watch: " + mNodeId);

            mGoogleApiClient.disconnect();
        }
    }).start();
}
 
Example #27
Source File: LoginActivity.java    From rnd-android-wear-tesla with MIT License 6 votes vote down vote up
private void retrieveWearableDeviceNode() {
    new Thread(new Runnable() {
        @Override
        public void run() {
            if (mGoogleApiClient != null && !(mGoogleApiClient.isConnected() || mGoogleApiClient.isConnecting()))
                mGoogleApiClient.blockingConnect(1000, TimeUnit.MILLISECONDS);

            NodeApi.GetConnectedNodesResult result =
                    Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();

            List<Node> nodes = result.getNodes();

            if (nodes.size() > 0)
                mNodeId = nodes.get(0).getId();

            Log.v("TAG", "Node ID of watch: " + mNodeId);

            mGoogleApiClient.disconnect();
        }
    }).start();
}
 
Example #28
Source File: SendByteArrayToNode.java    From ExceptionWear with Apache License 2.0 6 votes vote down vote up
public void run() {
    if ((objectArray.length / 1024) > 100) {
        throw new RuntimeException("Object is too big to push it via Google Play Services");
    }
    GoogleApiClient googleApiClient = SendWearManager.getInstance(context);
    googleApiClient.blockingConnect(WearExceptionTools.CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS);
    NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
    for (Node node : nodes.getNodes()) {
        MessageApi.SendMessageResult result;
        result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), WearExceptionTools.MESSAGE_EXCEPTION_PATH, objectArray).await();

        if (!result.getStatus().isSuccess()) {
            Log.v(WearExceptionTools.EXCEPTION_WEAR_TAG, "ERROR: failed to send Message via Google Play Services");
        }
    }
}
 
Example #29
Source File: QuizReportActionService.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onHandleIntent(Intent intent) {
    if (intent.getAction().equals(ACTION_RESET_QUIZ)) {
        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, "QuizListenerService failed to connect to GoogleApiClient.");
            return;
        }
        NodeApi.GetConnectedNodesResult nodes =
                Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
        for (Node node : nodes.getNodes()) {
            Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), RESET_QUIZ_PATH,
                    new byte[0]);
        }
    }
}
 
Example #30
Source File: SendByteArrayToNode.java    From BusWear with Apache License 2.0 6 votes vote down vote up
public void run() {
    GoogleApiClient googleApiClient = SendWearManager.getInstance(context);
    googleApiClient.blockingConnect(WearBusTools.CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS);
    NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
    for (Node node : nodes.getNodes()) {
        MessageApi.SendMessageResult result;
        if (sticky) {
            result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), WearBusTools.MESSAGE_PATH_STICKY + WearBusTools.CLASS_NAME_DELIMITER + clazzToSend.getName(), objectArray).await();
        } else {
            result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), WearBusTools.MESSAGE_PATH + WearBusTools.CLASS_NAME_DELIMITER + clazzToSend.getName(), objectArray).await();
        }
        if (!result.getStatus().isSuccess()) {
            Log.v(WearBusTools.BUSWEAR_TAG, "ERROR: failed to send Message via Google Play Services to node " + node.getDisplayName());
        }
    }
}