@SuppressWarnings("MissingPermission") void requestLocations() { PendingResult<Status> result= LocationServices.FusedLocationApi .requestLocationUpdates(getPlayServices(), request, this); result.setResultCallback(new ResultCallback<Status>() { @Override public void onResult(Status status) { if (status.isSuccess()) { Toast .makeText(getActivity(), R.string.location_req_success_msg, Toast.LENGTH_LONG) .show(); } else { Toast .makeText(getActivity(), status.getStatusMessage(), Toast.LENGTH_LONG) .show(); getActivity().finish(); } } }); }
@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();
private Collection<String> getNodes(GoogleApiClient googleApiClient) { HashSet<String> results = new HashSet<>(); NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(); for (Node node : nodes.getNodes()) { results.add(node.getId()); } return results; }
@Override public void seekTo(int windowIndex, long positionMs) { MediaStatus mediaStatus = getMediaStatus(); // We assume the default position is 0. There is no support for seeking to the default position // in RemoteMediaClient. positionMs = positionMs != C.TIME_UNSET ? positionMs : 0; if (mediaStatus != null) { if (getCurrentWindowIndex() != windowIndex) { remoteMediaClient.queueJumpToItem((int) currentTimeline.getPeriod(windowIndex, period).uid, positionMs, null).setResultCallback(seekResultCallback); } else { remoteMediaClient.seek(positionMs).setResultCallback(seekResultCallback); } pendingSeekCount++; pendingSeekWindowIndex = windowIndex; pendingSeekPositionMs = positionMs; for (EventListener listener : listeners) { listener.onPositionDiscontinuity(Player.DISCONTINUITY_REASON_SEEK); } } else if (pendingSeekCount == 0) { for (EventListener listener : listeners) { listener.onSeekProcessed(); } } }
@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(), STEP_COUNT_MESSAGES_PATH, stepCount.getBytes()).await(); //check if the message is delivered? Log.d("Messages Api", result.getStatus().isSuccess() ? "Sent successfully" : "Sent failed."); } } }).start();
private void requestSettings() { LocationSettingsRequest.Builder b= new LocationSettingsRequest.Builder() .addLocationRequest(request); PendingResult<LocationSettingsResult> result= LocationServices.SettingsApi.checkLocationSettings(getPlayServices(), b.build()); result.setResultCallback(this); }
public void run() { NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); String message = path + " was sent successfully"; if (bitmap.getByteCount() < MAX_SIZE) { for (Node node : nodes.getNodes()) { Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), path, stream.toByteArray()).await(); } } else { message = "Big image file, try to use another"; } mDataLayerListener.onSuccess(message); }
/** * Record the view end using the App Indexing API, disconnect the client once the view is * recorded. */ private void appIndexingRecordViewEnd() { final Uri appUri = getGameDeepLinkUri(); final String title = getGameTitle(); PendingResult<Status> result = AppIndex.AppIndexApi.viewEnd(mApiClient, this, appUri); result.setResultCallback( new ResultCallback<Status>() { @Override public void onResult(Status status) { mApiClient.disconnect(); // disconnecting here because of a potential race if (status.isSuccess()) { SantaLog.v( TAG, "App Indexing API: Recorded [" + title + "] view end successfully."); } else { SantaLog.e( TAG, "App Indexing API: There was an error recording the view end." + status.toString()); } } }); }
/** * Loads a bitmap from from a wearable data asset. Note, this is blocking. Do not call from the UI thread. * @param asset * @return bitmap, or null if the bitmap could not be loaded. */ public Bitmap loadBitmap(Asset asset) { Bitmap bitmap = null; if(mGoogleApiClient.isConnected()) { InputStream assetInputStream = Wearable.DataApi.getFdForAsset(mGoogleApiClient, asset).await().getInputStream(); bitmap = BitmapFactory.decodeStream(assetInputStream); } return bitmap; }
AppIndex.AppIndexApi.view(mApiClient, this, appUri, title, null, null); result.setResultCallback( new ResultCallback<Status>() { @Override
public void run() { NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleClient).await(); for (Node node : nodes.getNodes()) { MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(googleClient, node.getId(), path, message.getBytes()).await(); if (result.getStatus().isSuccess()) { Log.v(TAG, "SendThread: message send to " + node.getDisplayName()); } else { // Log an error Log.v(TAG, "SendThread: message failed to" + node.getDisplayName()); } } } }
protected final <T extends Result> void setupFitnessPendingResult(PendingResult<T> pendingResult, ResultCallback<T> resultCallback) { if(timeoutTime != null && timeoutUnit != null) { pendingResult.setResultCallback(resultCallback, timeoutTime, timeoutUnit); } else { pendingResult.setResultCallback(resultCallback); } }
private String getLocalNodeId() { NodeApi.GetLocalNodeResult nodeResult = Wearable.NodeApi.getLocalNode(mGoogleApiClient).await(); return nodeResult.getNode().getId(); }
protected final <T extends Result> void setupLocationPendingResult(PendingResult<T> pendingResult, ResultCallback<T> resultCallback) { if (timeoutTime != null && timeoutUnit != null) { pendingResult.setResultCallback(resultCallback, timeoutTime, timeoutUnit); } else { pendingResult.setResultCallback(resultCallback); } }
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; result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), 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()); } } } }
private void doPutMessageToNode(final String nodeId, final String path, final byte[] payload, final ResultCallback<MessageApi.SendMessageResult> callback) { PendingResult<MessageApi.SendMessageResult> pendingResult = Wearable.MessageApi.sendMessage(mGoogleApiClient, nodeId, path, payload); if (callback != null) { pendingResult.setResultCallback(callback); } }
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()); } } } }
/** * Gets the {@link com.google.android.gms.wearable.DataItem} at the given path on the node defined * in the given {@link android.net.Uri}. * * @param uri identifier used to specify a particular endpoint at the receiving node * @param callback for get result. */ public void getDataItem(Uri uri, ResultCallback<DataApi.DataItemResult> callback) { Wearable.DataApi.getDataItem(mGoogleApiClient, uri).setResultCallback(callback); }
private void sendMessageTest(Node node, String pathdesc, String path, byte[] payload) { JoH.benchmark(null); Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), path, payload).await();//Synchronous JoH.benchmark(pathdesc + " sendMessage len=" + payload.length); }