com.google.android.gms.location.LocationSettingsResult Java Examples

The following examples show how to use com.google.android.gms.location.LocationSettingsResult. 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: LocationSwitch.java    From react-native-location-switch with Apache License 2.0 6 votes vote down vote up
public void displayLocationSettingsRequest(final Activity activity) {
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(activity)
            .addApi(LocationServices.API).build();
    googleApiClient.connect();

    LocationRequest locationRequest = LocationRequest.create();
    locationRequest.setPriority(mAccuracy);
    locationRequest.setInterval(mInterval);
    locationRequest.setFastestInterval(mInterval / 2);

    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(locationRequest);
    builder.setAlwaysShow(false);

    final PendingResult<LocationSettingsResult> result =
            LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
    result.setResultCallback(new LocationResultCallback(activity));
}
 
Example #2
Source File: LocationSwitch.java    From react-native-location-switch with Apache License 2.0 6 votes vote down vote up
@Override
public void onResult(LocationSettingsResult result) {
    final Status status = result.getStatus();
    switch (status.getStatusCode()) {
        case LocationSettingsStatusCodes.SUCCESS:
            // All location settings are satisfied -> nothing to do
            callSuccessCallback();
            break;
        case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
            // Location settings are not satisfied. Show the user a dialog to upgrade location settings
            try {
                // Show the dialog by calling startResolutionForResult(), and check the result
                status.startResolutionForResult(mActivity, REQUEST_CHECK_SETTINGS);
            } catch (IntentSender.SendIntentException e) {
                Log.e(TAG, "PendingIntent unable to execute request.", e);
                callErrorCallback();
            }
            break;
        case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
            Log.e(TAG, "Location settings are inadequate, and cannot be fixed here. Dialog not created.");
            callErrorCallback();
            break;
    }
}
 
Example #3
Source File: TimeAttendantFastFragment.java    From iBeacon-Android with Apache License 2.0 6 votes vote down vote up
@Override
public void onResult(@NonNull LocationSettingsResult locationSettingsResult) {
    final Status status = locationSettingsResult.getStatus();
    switch (status.getStatusCode()) {
        case LocationSettingsStatusCodes.SUCCESS:
            Log.i(TAG, "All location settings are satisfied.");
            break;
        case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
            Log.i(TAG, "Location settings are not satisfied. Show the user a dialog to upgrade location settings ");

            try {
                // Show the dialog by calling startResolutionForResult(), and check the result
                // in onActivityResult().
                status.startResolutionForResult(getActivity(), REQUEST_CHECK_SETTINGS);
            } catch (IntentSender.SendIntentException e) {
                Log.i(TAG, "PendingIntent unable to execute request.");
            }
            break;
        case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
            Log.i(TAG, "Location settings are inadequate, and cannot be fixed here. Dialog not created.");
            break;
    }
}
 
Example #4
Source File: LocationController.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onConnected(Bundle bundle) {
    wasConnectedToPlayServices = true;
    try {
        if (Build.VERSION.SDK_INT >= 21) {
            LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
            PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
            result.setResultCallback(locationSettingsResult -> {
                final Status status = locationSettingsResult.getStatus();
                switch (status.getStatusCode()) {
                    case LocationSettingsStatusCodes.SUCCESS:
                        startFusedLocationRequest(true);
                        break;
                    case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                        Utilities.stageQueue.postRunnable(() -> {
                            if (lookingForPeopleNearby || !sharingLocations.isEmpty()) {
                                AndroidUtilities.runOnUIThread(() -> getNotificationCenter().postNotificationName(NotificationCenter.needShowPlayServicesAlert, status));
                            }
                        });
                        break;
                    case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                        Utilities.stageQueue.postRunnable(() -> {
                            playServicesAvailable = false;
                            try {
                                googleApiClient.disconnect();
                                start();
                            } catch (Throwable ignore) {

                            }
                        });
                        break;
                }
            });
        } else {
            startFusedLocationRequest(true);
        }
    } catch (Throwable e) {
        FileLog.e(e);
    }
}
 
Example #5
Source File: RxLocationSettings.java    From android-rxlocationsettings with Apache License 2.0 5 votes vote down vote up
@NonNull
public Single<Boolean> ensure(@NonNull LocationSettingsRequest request) {
  return rxLocationProvider.checkLocationSettings(request).toSingle()
      .flatMap(new Func1<LocationSettingsResult, Single<Boolean>>() {
        @Override
        public Single<Boolean> call(LocationSettingsResult result) {
          Status status = result.getStatus();
          if (status.hasResolution()) {
            return resolutionFragment.startResolutionForResult(status.getResolution());
          }
          return Single.just(status.isSuccess());
        }
      });
}
 
Example #6
Source File: MainActivity.java    From Android-nRF-BLE-Joiner with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void createLocationRequestForResult(){
    mLocationRequestBalancedPowerAccuracy = new LocationRequest();
    final LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(mLocationRequestBalancedPowerAccuracy)
            .setAlwaysShow(true);
    PendingResult<LocationSettingsResult> result =
            LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());

    result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
        @Override
        public void onResult(LocationSettingsResult locationSettingsResult) {
            Log.v("BLE", locationSettingsResult.getStatus().getStatusMessage());
            LocationSettingsStates states = locationSettingsResult.getLocationSettingsStates();
            if(states.isLocationUsable()) {
                checkForLocationPermissionsAndScan();
                return;
            }

            final Status status = locationSettingsResult.getStatus();
            switch(status.getStatusCode()){
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    mLocationServicesRequestApproved = false;
                    try {
                        status.startResolutionForResult(MainActivity.this, REQUEST_LOCATION_SERVICES);
                    } catch (IntentSender.SendIntentException e) {
                        e.printStackTrace();
                    }
                    break;
                case LocationSettingsStatusCodes.SUCCESS:
                    mLocationServicesRequestApproved = true;
                    checkForLocationPermissionsAndScan();
                    break;
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                    showPermissionRationaleFragment(R.string.rationale_location_cancel_message, 0);
                    break;
            }
        }
    });
}
 
Example #7
Source File: MainActivity.java    From Android-Fused-location-provider-example with Apache License 2.0 5 votes vote down vote up
private void startLocationUpdates() {
    Log.i(TAG, "startLocationUpdates");

    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(mLocationRequest);
    // 現在位置の取得の前に位置情報の設定が有効になっているか確認する
    PendingResult<LocationSettingsResult> result =
            LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
    result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
        @Override
        public void onResult(@NonNull LocationSettingsResult locationSettingsResult) {
            final Status status = locationSettingsResult.getStatus();

            switch (status.getStatusCode()) {
                case LocationSettingsStatusCodes.SUCCESS:
                    // 設定が有効になっているので現在位置を取得する
                    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, MainActivity.this);
                    }
                    break;
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    // 設定が有効になっていないのでダイアログを表示する
                    try {
                        status.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS);
                    } catch (IntentSender.SendIntentException e) {
                        // Ignore the error.
                    }
                    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.
                    break;
            }
        }
    });
}
 
Example #8
Source File: TimeAttendantFastFragment.java    From iBeacon-Android with Apache License 2.0 5 votes vote down vote up
private synchronized void displayLocationSettingsRequest() {

        LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
        builder.setAlwaysShow(true);

        //for fix deprecate code -> https://developers.google.com/android/reference/com/google/android/gms/location/SettingsClient
        PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
        result.setResultCallback(this);
    }
 
Example #9
Source File: SettingsCheckSingleOnSubscribe.java    From RxGps with Apache License 2.0 5 votes vote down vote up
@Override
protected void onGoogleApiClientReady(GoogleApiClient apiClient, SingleEmitter<LocationSettingsResult> emitter) {
    setupLocationPendingResult(
            LocationServices.SettingsApi.checkLocationSettings(apiClient, locationSettingsRequest),
            SingleResultCallBack.get(emitter)
    );
}
 
Example #10
Source File: LocationSettings.java    From RxGps with Apache License 2.0 4 votes vote down vote up
private Single<LocationSettingsResult> checkInternal(LocationSettingsRequest locationSettingsRequest, Long timeoutTime, TimeUnit timeoutUnit) {
    return Single.create(new SettingsCheckSingleOnSubscribe(rxLocation, locationSettingsRequest, timeoutTime, timeoutUnit));
}
 
Example #11
Source File: LocationSettings.java    From RxGps with Apache License 2.0 4 votes vote down vote up
public Single<LocationSettingsResult> check(@NonNull LocationSettingsRequest locationSettingsRequest, long timeoutTime, @NonNull TimeUnit timeoutUnit) {
    return checkInternal(locationSettingsRequest, timeoutTime, timeoutUnit);
}
 
Example #12
Source File: LocationSettings.java    From RxGps with Apache License 2.0 4 votes vote down vote up
public Single<LocationSettingsResult> check(@NonNull LocationSettingsRequest locationSettingsRequest) {
    return checkInternal(locationSettingsRequest, null, null);
}
 
Example #13
Source File: LocationAvailableAsyncEmitter.java    From Forage with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void call(AsyncEmitter<Void> locationAsyncEmitter) {

    GoogleApiClient.OnConnectionFailedListener onConnectionFailedListener = connectionResult ->
            locationAsyncEmitter.onError(new LocationUnavailableException("Failed to connect to Google Play Services!"));

    ResultCallback<LocationSettingsResult> pendingResultCallback = locationSettingsResult -> {
        Status status = locationSettingsResult.getStatus();
        if (status.getStatusCode() == LocationSettingsStatusCodes.SUCCESS) {
            locationAsyncEmitter.onCompleted();
        } else {
            locationAsyncEmitter.onError(new LocationUnavailableException("Location services not enabled!"));
        }
    };

    GoogleApiClient.ConnectionCallbacks connectionCallbacks = new GoogleApiClient.ConnectionCallbacks() {
        @Override
        public void onConnected(@Nullable Bundle bundle) {
            try {
                LocationRequest request = LocationRequest.create()
                        .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

                LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
                        .addLocationRequest(request)
                        .setAlwaysShow(true);

                PendingResult<LocationSettingsResult> result =
                        LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());

                result.setResultCallback(pendingResultCallback);

            } catch (SecurityException e) {
                locationAsyncEmitter.onError(new LocationUnavailableException("Location permission not available?"));
            }
        }

        @Override
        public void onConnectionSuspended(int i) {
            locationAsyncEmitter.onError(new LocationUnavailableException("Connection lost to Google Play Services"));

        }
    };

    googleApiClient.registerConnectionCallbacks(connectionCallbacks);
    googleApiClient.registerConnectionFailedListener(onConnectionFailedListener);
    googleApiClient.connect();

    locationAsyncEmitter.setCancellation(() -> {
        googleApiClient.unregisterConnectionCallbacks(connectionCallbacks);
        googleApiClient.unregisterConnectionFailedListener(onConnectionFailedListener);
    });
}
 
Example #14
Source File: LocationSettings.java    From RxGps with Apache License 2.0 4 votes vote down vote up
public Single<LocationSettingsResult> check(@NonNull LocationRequest locationRequest, long timeoutTime, @NonNull TimeUnit timeoutUnit) {
    return checkInternal(getLocationSettingsRequestBuilder().addLocationRequest(locationRequest).build(), timeoutTime, timeoutUnit);
}
 
Example #15
Source File: LocationSettings.java    From RxGps with Apache License 2.0 4 votes vote down vote up
public Single<LocationSettingsResult> check(@NonNull LocationRequest locationRequest) {
    return checkInternal(getLocationSettingsRequestBuilder().addLocationRequest(locationRequest).build(), null, null);
}
 
Example #16
Source File: SettingsApiImpl.java    From android_external_GmsLib with Apache License 2.0 4 votes vote down vote up
@Override
public PendingResult<LocationSettingsResult> checkLocationSettings(GoogleApiClient client, LocationSettingsRequest locationSettingsRequest) {
    return new InstantPendingResult<LocationSettingsResult>(new LocationSettingsResult(Status.CANCELED));
}
 
Example #17
Source File: GoogleLocationManagerServiceImpl.java    From android_packages_apps_GmsCore with Apache License 2.0 4 votes vote down vote up
@Override
public void requestLocationSettingsDialog(LocationSettingsRequest settingsRequest, ISettingsCallbacks callback, String packageName) throws RemoteException {
    Log.d(TAG, "requestLocationSettingsDialog: " + settingsRequest);
    PackageUtils.getAndCheckCallingPackage(context, packageName);
    callback.onLocationSettingsResult(new LocationSettingsResult(new LocationSettingsStates(true, true, false, true, true, false), Status.SUCCESS));
}