private void handleLocationStatusResult(@NonNull Status status) { if (mResolvingError) { // Already attempting to resolve an error. return; } if (status.getStatusCode() == LocationSettingsStatusCodes.RESOLUTION_REQUIRED) { try { status.startResolutionForResult(this, REQUEST_RESOLVE_ERROR); // TODO: mieux gérer mResolvingError (attendre la résolution) mResolvingError = true; } catch (IntentSender.SendIntentException e) { // There was an error with the resolution intent. Try again. // TODO: mieux notifier le service // mGoogleApiClient.connect(); MainActivity.this.startService(mCollecteServiceIntent); mResolvingError = false; } } else { // TODO: couper l'application ? mResolvingError = true; showErrorDialog(status.getStatusCode()); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) { if (resultCode == RESULT_OK) { Place pl = PlaceAutocomplete.getPlace(this, data); location.setText(pl.getName()); currentTrip.setLocation(pl.getName().toString()); currentTrip.setLat(pl.getLatLng().latitude); currentTrip.setLng(pl.getLatLng().longitude); currentTrip.setPlaceId(pl.getId()); Log.i(TAG, "onActivityResult: " + pl.getName() + "/" + pl.getAddress()); } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) { Status stat = PlaceAutocomplete.getStatus(this, data); Log.d(TAG, "onActivityResult: "); } else if (requestCode == RESULT_CANCELED){ System.out.println("Cancelled by the user"); } } else super.onActivityResult(requestCode, resultCode, data); }
@Override protected void onGoogleApiClientReady(GoogleApiClient apiClient, final Observer<? super Status> observer) { LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, locationRequest, intent) .setResultCallback(new ResultCallback<Status>() { @Override public void onResult(Status status) { if (!status.isSuccess()) { observer.onError(new StatusException(status)); } else { observer.onNext(status); observer.onCompleted(); } } }); }
private void setMockMode(boolean toggle) { if (toggle) { mockLocationSubscription = Observable.zip(locationProvider.mockLocation(mockLocationObservable), mockLocationObservable, new Func2<Status, Location, String>() { int count = 0; @Override public String call(Status result, Location location) { return new LocationToStringFunc().call(location) + " " + count++; } }) .subscribe(new DisplayTextOnViewAction(mockLocationView), new ErrorHandler()); } else { mockLocationSubscription.unsubscribe(); } }
private void addGeofence() { final GeofencingRequest geofencingRequest = createGeofencingRequest(); if (geofencingRequest == null) return; final PendingIntent pendingIntent = createNotificationBroadcastPendingIntent(); reactiveLocationProvider .removeGeofences(pendingIntent) .flatMap(new Func1<Status, Observable<Status>>() { @Override public Observable<Status> call(Status pendingIntentRemoveGeofenceResult) { return reactiveLocationProvider.addGeofences(pendingIntent, geofencingRequest); } }) .subscribe(new Action1<Status>() { @Override public void call(Status addGeofenceResult) { toast("Geofence added, success: " + addGeofenceResult.isSuccess()); } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { toast("Error adding geofence."); Log.d(TAG, "Error adding geofence.", throwable); } }); }
@NonNull @Override public Result await() { if (!canceled && latch != null) { try { latch.await(); } catch (InterruptedException e) { return new Result() { @Override public Status getStatus() { return Canceled; } }; } } return new Result() { @Override public Status getStatus() { return canceled ? Canceled : Success; } }; }
private void nearbySubscribe() { SubscribeOptions options = new SubscribeOptions.Builder() .setStrategy(PUB_SUB_STRATEGY) .setCallback(new SubscribeCallback() { @Override public void onExpired() { super.onExpired(); Log.i(TAG, "No longer subscribing"); } }).build(); Log.i(TAG, "Subscribing."); Nearby.Messages.subscribe(mGoogleApiClient, mMessageListener, options) .setResultCallback(new ResultCallback<Status>() { @Override public void onResult(@NonNull Status status) { if (status.isSuccess()) { Log.i(TAG, "Subscribed successfully."); emitSubscription("subscribe.onResult", "Subscribed successfully."); } else { Log.i(TAG, "Could not subscribe, status = " + status); emitSubscription("subscribe.onResultErr", "Could not subscribe, status = " + status); } } }); }
protected void registerFence(final String fenceKey, final AwarenessFence fence) { Awareness.FenceApi.updateFences( client, new FenceUpdateRequest.Builder() .addFence(fenceKey, fence, myPendingIntent) //Add fence to the pendingIntent .build()) .setResultCallback(new ResultCallback<Status>() { @Override public void onResult(@NonNull Status status) { if (status.isSuccess()) { Log.e(fenceKey, "Fence was successfully registered."); } else { Log.e(fenceKey, "Fence could not be registered: " + status); } } }); }
protected void unregisterFence(final String fenceKey) { Awareness.FenceApi.updateFences( client, new FenceUpdateRequest.Builder() .removeFence(fenceKey) .build()).setResultCallback(new ResultCallback<Status>() { @Override public void onResult(@NonNull Status status) { if (status.isSuccess()) { Log.e("Fence", "Fence " + fenceKey + " successfully removed."); } else { Log.e("Fence", "Fence " + fenceKey + " can not be removed."); } } }); }
private ArrayList<AutocompletePrediction> getAutocomplete(CharSequence constraint) { if (mGoogleApiClient.isConnected()) { PendingResult<AutocompletePredictionBuffer> results = Places.GeoDataApi .getAutocompletePredictions(mGoogleApiClient, constraint.toString(), mBounds, mPlaceFilter); AutocompletePredictionBuffer autocompletePredictions = results .await(60, TimeUnit.SECONDS); final Status status = autocompletePredictions.getStatus(); if (!status.isSuccess()) { Toast.makeText(getContext(), "Error contacting API: " + status.toString(), Toast.LENGTH_SHORT).show(); autocompletePredictions.release(); return null; } return DataBufferUtils.freezeAndClose(autocompletePredictions); } return null; }
public Observable<PlacePrediction> getAutocompleteResults(final GoogleApiClient mGoogleApiClient, final String query, final LatLngBounds bounds) { return Observable.create(new Observable.OnSubscribe<PlacePrediction>() { @Override public void call(Subscriber<? super PlacePrediction> subscriber) { PendingResult<AutocompletePredictionBuffer> results = Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, query, bounds, null); AutocompletePredictionBuffer autocompletePredictions = results .await(60, TimeUnit.SECONDS); final Status status = autocompletePredictions.getStatus(); if (!status.isSuccess()) { autocompletePredictions.release(); subscriber.onError(null); } else { for (AutocompletePrediction autocompletePrediction : autocompletePredictions) { subscriber.onNext( new PlacePrediction( autocompletePrediction.getPlaceId(), autocompletePrediction.getDescription() )); } autocompletePredictions.release(); subscriber.onCompleted(); } } }); }
@NonNull @Override public Result await(long l, @NonNull TimeUnit timeUnit) { if (!canceled && latch != null) { try { latch.await(l, timeUnit); } catch (InterruptedException e) { return new Result() { @Override public Status getStatus() { return Canceled; } }; } } return new Result() { @Override public Status getStatus() { return canceled ? Canceled : Success; } }; }
protected void signOut(GoogleApiClient googleApiClient){ mAuth.signOut(); Auth.GoogleSignInApi.signOut(googleApiClient).setResultCallback(new ResultCallback<Status>() { @Override public void onResult(@NonNull Status status) { Toast toast = Toast.makeText(AuthBaseActivity.this, mResources.getString(R.string.sign_out_text), Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 100); toast.show(); Intent i = new Intent(AuthBaseActivity.this, SignInActivity.class); AuthBaseActivity.this.startActivity(i); AuthBaseActivity.this.finish(); } }); }
/** * Sign the user out */ private void signOut() { Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(new ResultCallback<Status>() { /** * Result of signout attempt * @param status - the status of the signout */ @Override public void onResult(@NonNull Status status) { mAuth.signOut(); mController.resetDatabaseManager(); Intent resultIntent = new Intent(); setResult(RESULT_OK, resultIntent); finish(); } }); }
private ArrayList<AutocompletePrediction> getAutocomplete(CharSequence constraint) { if (mGoogleApiClient.isConnected()) { PendingResult<AutocompletePredictionBuffer> results = Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, constraint.toString(), mBounds, mPlaceFilter); AutocompletePredictionBuffer autocompletePredictions = results.await(60, TimeUnit.SECONDS); final Status status = autocompletePredictions.getStatus(); if (!status.isSuccess()) { Toast.makeText(getContext(), "Error contacting API: " + status.toString(), Toast.LENGTH_SHORT).show(); autocompletePredictions.release(); return null; } return DataBufferUtils.freezeAndClose(autocompletePredictions); } return null; }
protected Void doInBackground(Void... params) { // Create a new dataset and insertion request. DataSet dataSet = this.WeightsDataset; // [START insert_dataset] // Then, invoke the History API to insert the data and await the result, which is // possible here because of the {@link AsyncTask}. Always include a timeout when calling // await() to prevent hanging that can occur from the service being shutdown because // of low memory or other conditions. //Log.i(TAG, "Inserting the dataset in the History API."); com.google.android.gms.common.api.Status insertStatus = Fitness.HistoryApi.insertData(googleFitManager.getGoogleApiClient(), dataSet) .await(1, TimeUnit.MINUTES); // Before querying the data, check to see if the insertion succeeded. if (!insertStatus.isSuccess()) { //Log.i(TAG, "There was a problem inserting the dataset."); return null; } //Log.i(TAG, "Data insert was successful!"); return null; }
@Override protected void onConnected() { PendingResult<Status> pendingResult = null; String actionStr = null; if (mAction == SUBSCRIBE) { pendingResult = Nearby.Messages.subscribe( getGoogleApiClient(), createNearbySubscribeIntent(), createSubscribeOptions()); actionStr = "background subscribe"; } else { pendingResult = Nearby.Messages.unsubscribe( getGoogleApiClient(), createNearbySubscribeIntent()); actionStr = "background unsubscribe"; } pendingResult.setResultCallback(new SimpleResultCallback(actionStr) { @Override public void onResult(final Status status) { super.onResult(status); disconnect(); if (mCallback != null) { mCallback.run(); } } }); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) { if (resultCode == RESULT_OK) { Place pl = PlaceAutocomplete.getPlace(this, data); location.setText(pl.getAddress()); Log.i(TAG, "onActivityResult: " + pl.getName() + "/" + pl.getAddress()); } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) { Status stat = PlaceAutocomplete.getStatus(this, data); Log.d(TAG, "onActivityResult: "); } else if (requestCode == RESULT_CANCELED){ System.out.println("Cancelled by the user"); } } else super.onActivityResult(requestCode, resultCode, data); }
@SuppressWarnings({"MissingPermission"}) public void startLocationUpdates(GoogleApiClient googleApiClient) { // particular case:hace un requestLocationSettings y casi al mismo tiempo stop(), // ,se recibe settingsResult:SUCCESS y luego hace startLocationUpdates y como // no está conectado da error if (!googleApiClient.isConnected()) { return; } PendingResult<Status> result = LocationServices.FusedLocationApi.requestLocationUpdates( googleApiClient, mLocationRequest, this); result.setResultCallback(new ResultCallback<Status>() { @Override public void onResult(@NonNull Status status) { if (!status.isSuccess()) { Utils.logD(LOG_TAG, String.format("requestLocationUpdates returned an error:code:%s ," + "message: %s", status.getStatusCode(), status.getStatusMessage())); getActivity().finish(); } } }, 2, TimeUnit.SECONDS); }
/** * Sends the <code>message</code> on the data channel for the <code>namespace</code>. If fails, * it will call <code>onMessageSendFailed</code> * * @throws IllegalArgumentException If the the message is null, empty, or too long; or if the * namespace is null or too long. * @throws IllegalStateException If there is no active service connection. * @throws IOException */ public void sendDataMessage(String message, String namespace) throws IllegalArgumentException, IllegalStateException, IOException { checkConnectivity(); if (TextUtils.isEmpty(namespace)) { throw new IllegalArgumentException("namespace cannot be empty"); } Cast.CastApi.sendMessage(mApiClient, namespace, message). setResultCallback(new ResultCallback<Status>() { @Override public void onResult(Status result) { if (!result.isSuccess()) { DataCastManager.this.onMessageSendFailed(result); } } }); }
private ArrayList<AutocompletePrediction> getAutocomplete(CharSequence constraint) { if (mGoogleApiClient.isConnected()) { PendingResult<AutocompletePredictionBuffer> results = Places.GeoDataApi .getAutocompletePredictions(mGoogleApiClient, constraint.toString(), mBounds, mPlaceFilter); AutocompletePredictionBuffer autocompletePredictions = results .await(60, TimeUnit.SECONDS); final Status status = autocompletePredictions.getStatus(); if (!status.isSuccess()) { if (callback != null) callback.onSuggestFail(status); autocompletePredictions.release(); return null; } return DataBufferUtils.freezeAndClose(autocompletePredictions); } return null; }
@Override public void onResult(@NonNull LocationSettingsResult locationSettingsResult) { final Status status = locationSettingsResult.getStatus(); switch (status.getStatusCode()) { case LocationSettingsStatusCodes.SUCCESS: // All location settings are satisfied. The client can // initialize location requests here. continueGPSOperation(); break; case LocationSettingsStatusCodes.RESOLUTION_REQUIRED: // Location settings are not satisfied, but this can be fixed // by showing the user a dialog. _result.error("LOCATION DISABLED", "This Android device has it's location disabled", null); break; case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE: // Location settings are not satisfied. However, we have no way // to fix the settings so we won't show the dialog. _result.error("LOCATION DISABLED", "This Android device has it's location disabled", null); break; } }
/** * Sends the <code>message</code> on the data channel for the namespace that was provided * during the initialization of this class. If <code>messageId > 0</code>, then it has to be * a unique identifier for the message; this id will be returned if an error occurs. If * <code>messageId == 0</code>, then an auto-generated unique identifier will be created and * returned for the message. * * @throws IllegalStateException If the namespace is empty or null * @throws NoConnectionException If no connectivity to the device exists * @throws TransientNetworkDisconnectionException If framework is still trying to recover from * a possibly transient loss of network */ public void sendDataMessage(String message) throws TransientNetworkDisconnectionException, NoConnectionException { if (TextUtils.isEmpty(mDataNamespace)) { throw new IllegalStateException("No Data Namespace is configured"); } checkConnectivity(); Cast.CastApi.sendMessage(mApiClient, mDataNamespace, message) .setResultCallback(new ResultCallback<Status>() { @Override public void onResult(Status result) { if (!result.isSuccess()) { VideoCastManager.this.onMessageSendFailed(result.getStatusCode()); } } }); }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case LOAD_PAYMENT_DATA_REQUEST_CODE: switch (resultCode) { case Activity.RESULT_OK: PaymentData paymentData = PaymentData.getFromIntent(data); handlePaymentSuccess(paymentData); break; case Activity.RESULT_CANCELED: // Nothing to here normally - the user simply cancelled without selecting a // payment method. break; case AutoResolveHelper.RESULT_ERROR: Status status = AutoResolveHelper.getStatusFromIntent(data); handleError(status.getStatusCode()); break; } // Re-enables the Pay with Google button. mPwgButton.setClickable(true); break; } }
void handleIntent() { Status status = getIntent().getParcelableExtra(ARG_STATUS); try { status.startResolutionForResult(this, REQUEST_CODE_RESOLUTION); } catch (IntentSender.SendIntentException | NullPointerException e) { setResolutionResultAndFinish(Activity.RESULT_CANCELED); } }
@Override protected void onGoogleApiClientReady(GoogleApiClient apiClient, final Observer<? super Status> observer) { LocationServices.GeofencingApi.addGeofences(apiClient, request, geofenceTransitionPendingIntent) .setResultCallback(new ResultCallback<Status>() { @Override public void onResult(Status status) { if (status.isSuccess()) { observer.onNext(status); observer.onCompleted(); } else { observer.onError(new StatusException(status)); } } }); }
@Override protected void removeGeofences(GoogleApiClient locationClient, final Observer<? super Status> observer) { LocationServices.GeofencingApi.removeGeofences(locationClient, pendingIntent) .setResultCallback(new ResultCallback<Status>() { @Override public void onResult(Status status) { if (status.isSuccess()) { observer.onNext(status); observer.onCompleted(); } else { observer.onError(new StatusException(status)); } } }); }
@Override public void onResult(TurnBasedMultiplayer.InitiateMatchResult result) { // Check if the status code is not success. Status status = result.getStatus(); if (!status.isSuccess()) { Log.d("##MACHINITIATEDCALLBACK","errore!"); return; } TurnBasedMatch match = result.getMatch(); // If this player is not the first player in this match, continue. if (match.getData() != null) { Log.d("##MACHINITIATEDCALLBACK","WAITING FOR MY TURN"); return; } // Otherwise, this is the first player. Initialize the game state. Log.d("##MACHINITIATEDCALLBACK","GAME STARTED"); //initGame(match); // Let the player take the first turn Log.d("##MACHINITIATEDCALLBACK","showTurnUi"); //showTurnUI(match); }
@Override protected void onGoogleApiClientReady(GoogleApiClient apiClient, final Observer<? super Status> observer) { LocationServices.FusedLocationApi.removeLocationUpdates(apiClient, intent) .setResultCallback(new ResultCallback<Status>() { @Override public void onResult(Status status) { if (status.isSuccess()) { observer.onNext(status); observer.onCompleted(); } else { observer.onError(new StatusException(status)); } } }); }
private void revokeAccess() { Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient).setResultCallback( new ResultCallback<Status>() { @Override public void onResult(Status status) { updateUI(false); } }); }
public void addGeofencingRequest() { if (geofencingRequest == null) { return; } if (this.mGoogleAPIClient == null || !this.mGoogleAPIClient.isConnected()) { this.addGeofencingRequest = true; setupGoogleAPIClient(); return; } try { Intent geofencingIntent = new Intent(mContext, GeofenceTransitionsIntentService.class); mGeofencePendingIntent = PendingIntent.getService(mContext, 0, geofencingIntent, PendingIntent.FLAG_UPDATE_CURRENT); LocationServices.GeofencingApi.addGeofences(mGoogleAPIClient, geofencingRequest, mGeofencePendingIntent).setResultCallback(new ResultCallback<Status>() { @Override public void onResult(@NonNull Status status) { if (status.isSuccess()) { HyperLog.i(TAG, "Geofence set at Expected Place"); addGeofencingRequest = false; } else { HyperLog.e(TAG, "Geofence error at Expected Place" + status.getStatusMessage()); addGeofencingRequest = true; } } }); } catch (SecurityException | IllegalArgumentException exception) { HyperLog.e(TAG, "Geofence error at Expected Place" + exception.getMessage()); CrashlyticsWrapper.log(exception); } }
@Override public void cancel() { if (listener != null) { listener.onResult(new Result() { @Override public Status getStatus() { return new Status(CommonStatusCodes.CANCELED); } }); } innerResult.cancel(); }
@Override protected void onGoogleApiClientReady(GoogleApiClient apiClient, SingleEmitter<Status> emitter) { //noinspection MissingPermission setupLocationPendingResult( LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, locationRequest, pendingIntent), SingleResultCallBack.get(emitter) ); }