Java 类com.google.android.gms.location.LocationSettingsRequest 实例源码

项目:react-native-location-switch    文件:LocationSwitch.java   
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));
}
项目:civify-app    文件:LocationAdapter.java   
private void updateLocation() {
    Log.v(TAG, "Trying to update location...");
    if (isDelayedUpdate()) Log.v(TAG, "Detected delayed updates.");
    else {
        if (checkConnection()) {
            if (hasPermissions()) {
                setRequestingPermissions(true);
                LocationSettingsRequest.Builder builder =
                        new LocationSettingsRequest.Builder().addLocationRequest(
                                getLocationRequest()).setAlwaysShow(true);

                LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient,
                        builder.build()).setResultCallback(getLocationSettingsResultCallback());
                Log.v(TAG, "Settings verification requested.");
            } else checkForPermissions();
        }
    }
}
项目:2017.2-codigo    文件:FusedLocationMapActivity.java   
@Override
public void onConnected(Bundle bundle) {

    //inicializa list view
    adapter=new ArrayAdapter<Location>(this, android.R.layout.simple_list_item_1, data);
    setListAdapter(adapter);

    //define requisicao para obter localizacao
    //objeto define quantos updates serao necessarios
    //deadline para desistir se nao conseguir obter location
    //intervalo
    //otimizacao de energia, caso aplicavel
    locationRequest = new LocationRequest()
            .setNumUpdates(5)
            .setExpirationDuration(60000)
            .setInterval(1000)
            .setPriority(LocationRequest.PRIORITY_LOW_POWER);


    LocationSettingsRequest.Builder b = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
    PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(playServices, b.build());
    result.setResultCallback(this);
}
项目:proto-collecte    文件:MainActivity.java   
@Override
public void onConnected(@Nullable Bundle bundle) {
    LocationRequest locationRequest = createLocationRequest();
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
    PendingResult<LocationSettingsResult> locationSettingsResultPendingResult = LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
    locationSettingsResultPendingResult
            .setResultCallback(new ResultCallback<LocationSettingsResult>() {
                @Override
                public void onResult(LocationSettingsResult result) {
                    if (LocationSettingsStatusCodes.SUCCESS != result.getStatus().getStatusCode()) {
                        if (result.getStatus().hasResolution()) {
                            handleLocationStatusResult(result.getStatus());
                        } else {
                            // TODO: faire quelque chose
                        }
                    }
                }
            });
    if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // la demande des droits est faite ailleurs
        return;
    }
    LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, locationRequest, this);
    onLocationChanged(LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient));
}
项目:proto-collecte    文件:ParcoursService.java   
private void configureLocationConnection() {
    LocationRequest locationRequest = createLocationRequest();
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
    PendingResult<LocationSettingsResult> locationSettingsResultPendingResult = LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
    locationSettingsResultPendingResult
            .setResultCallback(new ResultCallback<LocationSettingsResult>() {
                @Override
                public void onResult(LocationSettingsResult result) {
                    if (LocationSettingsStatusCodes.SUCCESS != result.getStatus().getStatusCode()) {
                        Intent localIntent = new Intent(Constants.GOOGLE_API).putExtra(Constants.GOOGLE_API_LOCATION_RESULT, result.getStatus());
                        LocalBroadcastManager.getInstance(ParcoursService.this).sendBroadcast(localIntent);
                    }
                }
            });
    // noinspection MissingPermission : permissions dans le manifest
    LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, locationRequest, this);
}
项目:AstronomyTourPadova    文件:GmapFragment.java   
private void setupGeoLocation() {
    Log.d(TAG, "setupGeoLocation()");

    mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
        .addApi(LocationServices.API)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .build();
    mGoogleApiClient.connect();

    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(10 * 60 * 1000);        // 10 minutes, in milliseconds
    mLocationRequest.setFastestInterval(60 * 1000);  // 60 second, in milliseconds
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); // We wanto to center the Player on his actual position

    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
    builder.addLocationRequest(mLocationRequest);
    builder.setAlwaysShow(true); // "This app wants to change your device settings for GPS location"
    mLocationSettingsRequest = builder.build();
}
项目:react-native-connectivity-status    文件:RNConnectivityStatusModule.java   
/**
 * GoogleApiClient interfaces
 */
@Override
public void onConnected(@Nullable Bundle bundle) {
  final LocationRequest locationRequest = LocationRequest.create()
          .setPriority(LocationRequest.PRIORITY_LOW_POWER);

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

  final 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();
      if (status.getStatusCode() == LocationSettingsStatusCodes.RESOLUTION_REQUIRED) {
        try {
          status.startResolutionForResult(getCurrentActivity(), NEAR_LOCATION_SETTINGS_CODE);
        } catch (IntentSender.SendIntentException e) {
          e.printStackTrace();
        }
      }
    }
  });
}
项目:directly    文件:LocationRepositoryImpl.java   
public Observable<Location> getCurrentLocation() {
    if (ActivityCompat.checkSelfPermission(activity,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return Observable.error(new SecurityException("No location permission granted"));
    }
    LocationRequest locationRequest = LocationRequest.create().setInterval(200).setNumUpdates(1).setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    return locationProvider.checkLocationSettings(new LocationSettingsRequest.Builder().setAlwaysShow(true).addLocationRequest(locationRequest).build()).flatMap(locationSettingsResult -> {
        if (locationSettingsResult.getStatus().isSuccess()) {
            return locationProvider.getUpdatedLocation(locationRequest)
                    .doOnNext(location -> {
                        Timber.d("Location", location.toString());
                    })
                    .flatMap(locations -> getLocationFromLatLng(locations.getLatitude(), locations.getLongitude()));
        } else {
            try {
                fragment.startIntentSenderForResult(locationSettingsResult.getStatus().getResolution().getIntentSender(), locationRequestCode, null, 0, 0, 0, null);
            } catch (IntentSender.SendIntentException e) {
                return Observable.error(e);
            }
            return Observable.error(new RuntimeException("Location not enabled"));
        }
    }).subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread());
}
项目:corsaire    文件:NavigationService.java   
private void initService() {
    setNotification();

    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        Toast.makeText(NavigationService.this, getString(R.string.erreur_autorisation), Toast.LENGTH_SHORT).show();
        quit();
        return;
    }

    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    LocationRequest mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(2000);
    mLocationRequest.setFastestInterval(1000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(mLocationRequest);
    LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient,
            builder.build());


    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this);
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1, this);


}
项目:corsaire    文件:MyAddressService.java   
@Override
public void onConnected(@Nullable Bundle bundle) {
    LocationRequest mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(2000);
    mLocationRequest.setFastestInterval(1000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(mLocationRequest);
    LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient,
            builder.build());
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {

        }
    });
}
项目:corsaire    文件:MainActivity.java   
@Override
public void onConnected(@Nullable Bundle bundle) {
    LocationRequest mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(2000);
    mLocationRequest.setFastestInterval(1000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(mLocationRequest);
    LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient,
            builder.build());

    if (isExploreByTouchEnabled) {
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        ((CheckBox) findViewById(R.id.bus_checkbox)).setChecked(sharedPref.getBoolean(getString(R.string.pref_bus_key), false));
        checkSavedItinerary(); //Because for other, the check is done onMapReady
        Intent intent = new Intent(this, MyAddressService.class);
        startService(intent);
    } else {
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }


}
项目:GitHub    文件:ReactiveLocationProvider.java   
/**
 * Observable that can be used to check settings state for given location request.
 *
 * @param locationRequest location request
 * @return observable that emits check result of location settings
 * @see com.google.android.gms.location.SettingsApi
 */
public Observable<LocationSettingsResult> checkLocationSettings(final LocationSettingsRequest locationRequest) {
    return getGoogleApiClientObservable(LocationServices.API)
            .flatMap(new Func1<GoogleApiClient, Observable<LocationSettingsResult>>() {
                @Override
                public Observable<LocationSettingsResult> call(GoogleApiClient googleApiClient) {
                    return fromPendingResult(LocationServices.SettingsApi.checkLocationSettings(googleApiClient, locationRequest));
                }
            });
}
项目:LocGetter    文件:LocationGetterImpl.java   
private Status getLocationSettingsStatus(GoogleApiClient googleApiClient) {
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
    builder.setAlwaysShow(true);
    builder.addLocationRequest(locationRequest);
    PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
    return result.await().getStatus();
}
项目:flutter_geolocation    文件:GpsCoordinatesPlugin.java   
private void checkLocationEnabled() {
  LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
          .addLocationRequest(_locationRequest);
  PendingResult<LocationSettingsResult> result =
          LocationServices.SettingsApi.checkLocationSettings(_client,
                  builder.build());
  result.setResultCallback(new MyLocationSettingsCallback());
}
项目:android-rxlocationsettings    文件:RxLocationSettings.java   
@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());
        }
      });
}
项目:android-rxlocationsettings    文件:MainActivity.java   
private void ensureLocationSettings() {
  LocationSettingsRequest locationSettingsRequest = new LocationSettingsRequest.Builder()
      .addLocationRequest(LocationRequest.create().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY))
      .build();
  RxLocationSettings.with(this).ensure(locationSettingsRequest)
      .subscribe(new Action1<Boolean>() {
        @Override
        public void call(Boolean enabled) {
          Toast.makeText(MainActivity.this, enabled ? "Enabled" : "Failed", Toast.LENGTH_LONG).show();
        }
      });
}
项目:LocationAware    文件:LocationProvider.java   
public void setUpLocationRequest(OnSuccessListener<LocationSettingsResponse> successListener,
    OnFailureListener onFailureListener) {
  LocationRequest locationRequest = getLocationRequest();
  LocationSettingsRequest.Builder builder =
      new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
  SettingsClient settingsClient = LocationServices.getSettingsClient(context);
  Task<LocationSettingsResponse> locationSettingsResponseTask =
      settingsClient.checkLocationSettings(builder.build());

  locationSettingsResponseTask.addOnSuccessListener(successListener);

  locationSettingsResponseTask.addOnFailureListener(onFailureListener);
}
项目:proto-collecte    文件:CollecteService.java   
private void configureLocationConnection() {
        LocationRequest locationRequest = createLocationRequest();
        LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
        if (collecteActiverPref) {
            com.google.android.gms.common.api.PendingResult<LocationSettingsResult> locationSettingsResultPendingResult = LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
            locationSettingsResultPendingResult
                    .setResultCallback(new ResultCallback<LocationSettingsResult>() {
                        @Override
                        public void onResult(LocationSettingsResult result) {
                            if (LocationSettingsStatusCodes.SUCCESS != result.getStatus().getStatusCode()) {
                                Intent localIntent = new Intent(Constants.GOOGLE_API).putExtra(Constants.GOOGLE_API_LOCATION_RESULT, result.getStatus());
                                LocalBroadcastManager.getInstance(CollecteService.this).sendBroadcast(localIntent);
                            }
                        }
                    });
            // noinspection MissingPermission : permissions dans le manifest
            LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, locationRequest, this);
            //noinspection MissingPermission
//            mLocationManager.addNmeaListener(new GpsStatus.NmeaListener() {
//                @Override
//                public void onNmeaReceived(long l, String s) {
//                    boolean a = false;
//                }
//            });
        } else {
            LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
        }
    }
项目:Gps    文件:Gps4Activity.java   
@Override
public void onConnected(@Nullable Bundle bundle) {
    locationRequest=LocationRequest.create();
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setInterval(30*1000);
    locationRequest.setFastestInterval(5*1000);

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

    locationSettingsResultPendingResult=LocationServices.SettingsApi
            .checkLocationSettings(mGoogleApiClient,builder.build());
    locationSettingsResultPendingResult.setResultCallback(new ResultCallback<LocationSettingsResult>() {
        @Override
        public void onResult(@NonNull LocationSettingsResult locationSettingsResult) {

            final Status status=locationSettingsResult.getStatus();
            final LocationSettingsStates states=locationSettingsResult.getLocationSettingsStates();
            switch (status.getStatusCode()) {
                case LocationSettingsStatusCodes.SUCCESS:
                    //All location settings are satisfied. The client can initialize location requests here
                    break;
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    //Location settings are not satisfied but could be fixed by showing user a dialog
                    try {
                        status.startResolutionForResult(Gps4Activity.this,REQUEST_LOCATION);
                    } catch (IntentSender.SendIntentException e) {
                        e.printStackTrace();
                    }
                    break;
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                    //Location settings are not satisfied and we have no way to fix the settings
                    //so we cannot show the dialog
                    break;
            }
        }
    });
}
项目:AstronomyTourPadova    文件:LocationService.java   
@Override
public void onCreate() {
    Log.d(TAG, "onCreate");
    googleApiClient = new GoogleApiClient.Builder(this)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .addApi(LocationServices.API)
        .build();
    googleApiClient.connect();

    createLocationRequest("highest");

    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
    builder.addLocationRequest(locationRequest);
    builder.setAlwaysShow(true); // "This app wants to change your device settings for GPS location"
    locationSettingsRequest = builder.build();

    HandlerThread handlerThread = new HandlerThread(TAG);
    handlerThread.start();
    handler = new Handler(handlerThread.getLooper());
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    currentNotificationTitle = getResources().getString(R.string.app_name);
    currentNotificationText = getResources().getString(R.string.notification_desc);

    // Handling interaction with WiFi
    wifiConnected = Utils.isWifiConnected(getApplicationContext());

    // Listening to Network changes (WiFi mostly)
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction("android.net.wifi.WIFI_STATUS_CHANGED");
    intentFilter.addAction("android.net.wifi.STATUS_CHANGE");

    registerReceiver(AtNetworkReceiver, intentFilter);
}
项目:BLE-Indoor-Positioning    文件:AndroidLocationProvider.java   
private void setupLocationService() {
    Log.v(TAG, "Setting up location service");
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(getLocationRequest());
    SettingsClient client = LocationServices.getSettingsClient(activity);
    Task<LocationSettingsResponse> task = client.checkLocationSettings(builder.build());

    task.addOnSuccessListener(activity, new OnSuccessListener<LocationSettingsResponse>() {
        @Override
        public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
            Log.v(TAG, "Location settings satisfied");
        }
    });

    task.addOnFailureListener(activity, new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            int statusCode = ((ApiException) e).getStatusCode();
            switch (statusCode) {
                case CommonStatusCodes.RESOLUTION_REQUIRED:
                    Log.w(TAG, "Location settings not satisfied, attempting resolution intent");
                    try {
                        ResolvableApiException resolvable = (ResolvableApiException) e;
                        resolvable.startResolutionForResult(activity, REQUEST_CODE_LOCATION_SETTINGS);
                    } catch (IntentSender.SendIntentException sendIntentException) {
                        Log.e(TAG, "Unable to start resolution intent");
                    }
                    break;
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                    Log.w(TAG, "Location settings not satisfied and can't be changed");
                    break;
            }
        }
    });
}
项目:MapsWithPlacesAutoComplete    文件:MapsActivity.java   
/**
 * Method to check if GPS is on or not
 */
private void isGpsOn() {
    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:
                    getCurrentLocationAddress();
                    break;
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    try {
                        status.startResolutionForResult(
                                MapsActivity.this,
                                REQUEST_CHECK_SETTINGS);
                    } catch (IntentSender.SendIntentException e) {
                        Log.e(TAG, "Exception : " + e);
                    }
                    break;
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                    Log.e(TAG, "Location settings are not satisfied.");
                    break;
            }
        }
    });

}
项目:speedr    文件:MainActivity.java   
private void enableGPSViaPlayServices() {
    Crashlytics.log(Log.INFO, MainActivity.class.getSimpleName(), "enableGPSViaPlayServices()");

    googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(LocationServices.API)
            .build();
    googleApiClient.connect();

    LocationSettingsRequest locationSettingsRequest = new LocationSettingsRequest.Builder()
            .addLocationRequest(new LocationRequest().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY))
            .setAlwaysShow(true)
            .build();

    LocationServices.SettingsApi.checkLocationSettings(googleApiClient, locationSettingsRequest)
    .setResultCallback(new ResultCallback<LocationSettingsResult>() {
        @Override
        public void onResult(@NonNull LocationSettingsResult result) {
            boolean showingLocationSettingsDialog = false;
            if (result.getStatus().getStatusCode() == LocationSettingsStatusCodes.RESOLUTION_REQUIRED) {
                try {
                    //Show location settings change dialog and check the result in onActivityResult()
                    result.getStatus().startResolutionForResult(MainActivity.this, REQUEST_LOCATION);
                    showingLocationSettingsDialog = true;
                    Crashlytics.log(Log.INFO, MainActivity.class.getSimpleName(), "Showing PlayServices GPS settings dialog");
                } catch (Exception e) {
                    Crashlytics.log(Log.ERROR, MainActivity.class.getSimpleName(), "Error showing PlayServices GPS settings dialog");
                    Crashlytics.logException(e);
                }
            }
            if (!showingLocationSettingsDialog) {
                showNoGPSAlert(); //Ask user to manually enable GPS
                googleApiClient.disconnect();
            }
        }
    });
}
项目:WalkGraph    文件:MapFragmentImpl.java   
/**
 * Method to check for the location settings of the device,
 * if it doesn't fit the current requirement of the app
 * open the settings for user to change them, if the settings are OK, starts the TimeService.
 */

@Override
public void startLocationService() {
    LocationRequest request = new LocationRequest()
            .setFastestInterval(1500)
            .setInterval(3000)
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    LocationSettingsRequest.Builder settingsRequest = new LocationSettingsRequest.Builder();
    settingsRequest.addLocationRequest(request);

    SettingsClient client = LocationServices.getSettingsClient(getActivity());
    Task<LocationSettingsResponse> responseTask = client.checkLocationSettings
            (settingsRequest.build());

    responseTask.addOnSuccessListener(getActivity(), locationSettingsResponse ->
            locationScheduler());

    responseTask.addOnFailureListener(getActivity(), e -> {
        int statusCode = ((ApiException) e).getStatusCode();

        switch (statusCode){
            case CommonStatusCodes.RESOLUTION_REQUIRED:
                try {
                    ResolvableApiException apiException = ((ResolvableApiException)e);
                    apiException.startResolutionForResult(getActivity(), permissionCode);
                    Log.d(TAG, "Dialog displayed");
                }catch (IntentSender.SendIntentException sendIntentException){
                    Log.d(TAG, "Error displaying dialogBox", sendIntentException);
                }
                break;
            case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                Log.d(TAG, "Unable to turn on location service", e);

        }
    });
}
项目:GeoShare_Android    文件:MapsFragment.java   
private void locationSettingsRequest(Context context) {
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(context)
            .addApi(LocationServices.API).build();
    googleApiClient.connect();

    LocationRequest locationRequest = LocationRequest.create();
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setInterval(10000);
    locationRequest.setFastestInterval(10000/2);

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

    PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, 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:
                    System.out.println("ALL LOCATION SETTINGS ARE SATISFIED");
                    break;
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    try {
                        status.startResolutionForResult(getActivity(), 213);
                    } catch (IntentSender.SendIntentException e) {
                        e.printStackTrace();
                    }
                    break;
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                    System.out.println("STUFF");
                    break;
            }
        }
    });
}
项目:LocationAssistant    文件:LocationAssistant.java   
private void requestLocation() {
    if (!googleApiClient.isConnected() || !permissionGranted) return;
    locationRequest = LocationRequest.create();
    locationRequest.setPriority(priority);
    locationRequest.setInterval(updateInterval);
    locationRequest.setFastestInterval(updateInterval);
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(locationRequest);
    builder.setAlwaysShow(true);
    LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build())
            .setResultCallback(onLocationSettingsReceived);
}
项目:dashit    文件:LocationAssistant.java   
private void requestLocation() {
    if (!googleApiClient.isConnected() || !permissionGranted) return;
    locationRequest = LocationRequest.create();
    locationRequest.setPriority(priority);
    locationRequest.setInterval(updateInterval);
    locationRequest.setFastestInterval(updateInterval);
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(locationRequest);
    builder.setAlwaysShow(true);
    LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build())
            .setResultCallback(onLocationSettingsReceived);
}
项目:Android-Continuity    文件:BaseLocationActivity.java   
@Override
public void checkLocationSettings(LocationRequest locationRequest) {
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(locationRequest);
    PendingResult<LocationSettingsResult> result =
            LocationServices.SettingsApi.checkLocationSettings(mBaseGoogleApiClient, builder.build());
    result.setResultCallback(mLocationSettingsRequestResultCallback);
}
项目:Japp16    文件:LocationProviderService.java   
public void checkLocationSettings() {
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(request);
    PendingResult<LocationSettingsResult> result =
            LocationServices.SettingsApi.checkLocationSettings(client,
                    builder.build());
    result.setResultCallback(this);
}
项目:random-restaurant-generator    文件:LocationProviderHelper.java   
public LocationProviderHelper(final Activity act, FloatingSearchView infoBox,
                              GoogleApiClient googleApiClient) {
    this.activity = act;
    this.searchLocationBox = infoBox;
    this.mGoogleClient = googleApiClient;

    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(2000);
    mLocationRequest.setFastestInterval(1000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
    builder.addLocationRequest(mLocationRequest);
    builder.setAlwaysShow(true);
    mLocationSettingsRequest = builder.build();

    progressDialog = new ProgressDialog(this.activity);

    progressDialog.setMessage(this.activity.getString(R.string.string_getting_location));
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setCanceledOnTouchOutside(false);
    progressDialog.setCancelable(false);
    progressDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            dismissLocationUpdater();
            useGPS = false;
        }
    });
}
项目:Android-Fused-location-provider-example    文件:MainActivity.java   
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;
            }
        }
    });
}
项目:app    文件:MapsActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    //disable my location on default
    myLocationEnabled = false;

    //build and connect Google API client
    buildGoogleApiClient();

    if (!(apiClient.isConnected())) {
        apiClient.connect();
    }

    //build location settings request with city level accuracy (with PRIORITY_LOW_POWER)
    locationRequest = new LocationRequest();
    locationRequest.setPriority(LocationRequest.PRIORITY_LOW_POWER);
    //build LocationSettingsRequest
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
    builder.addLocationRequest(locationRequest);
    locationSettingsRequest = builder.build();

    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}
项目:Android-nRF-BLE-Joiner    文件:MainActivity.java   
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;
            }
        }
    });
}
项目:rxactivityresponse    文件:LocationSettingsObservable.java   
private void handleLocationSettings(final ResourceObserver<T> emitter, final GoogleApiClient client) {
    if (activityResultCanceled(STATE_NAME)) {
        emitter.onError(new LocationSettingDeniedException());
        return;
    }
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
        .setAlwaysShow(true)
        .addLocationRequest(locationRequest);

    PendingResult<LocationSettingsResult> pendingResult = LocationServices.SettingsApi.checkLocationSettings(client, builder.build());
    pendingResult.setResultCallback(new ResultCallback<LocationSettingsResult>() {
        @Override
        public void onResult(LocationSettingsResult result) {
            final Status status = result.getStatus();
            switch (status.getStatusCode()) {
                case LocationSettingsStatusCodes.SUCCESS:
                    locationSettingSuccess(emitter, client);
                    break;
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    resolveResolutionRequired(emitter, status);
                    emitter.onComplete();  // silently close our api connection, full restart through responsehandler required, so we can close this connection.
                    break;
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                    emitter.onError(new RxPlayServices.RxLocationError(LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE));
                    break;
            }
        }
    });
}
项目:random-restaurant-generator    文件:LocationProviderHelper.java   
public LocationProviderHelper(final Activity act, FloatingSearchView infoBox,
                              GoogleApiClient googleApiClient) {
    this.activity = act;
    this.searchLocationBox = infoBox;
    this.mGoogleClient = googleApiClient;

    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(2000);
    mLocationRequest.setFastestInterval(1000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
    builder.addLocationRequest(mLocationRequest);
    builder.setAlwaysShow(true);
    mLocationSettingsRequest = builder.build();

    progressDialog = new ProgressDialog(this.activity);

    progressDialog.setMessage(this.activity.getString(R.string.string_getting_location));
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setCanceledOnTouchOutside(false);
    progressDialog.setCancelable(false);
    progressDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            dismissLocationUpdater();
            useGPS = false;
        }
    });
}
项目:sprockets-android    文件:GoogleLocationProvider.java   
@Override
public Maybe<LocationSettingsResult> checkLocationSettings(int priority) {
    return Maybe.create(emitter -> {
        GoogleApiClient client = mBuilder.build();
        GoogleApiClients.connect(client, hint -> SettingsApi.checkLocationSettings(client,
                new LocationSettingsRequest.Builder()
                        .addLocationRequest(LocationRequest.create().setPriority(priority))
                        .setAlwaysShow(true).build()).setResultCallback(result -> {
            client.disconnect();
            emitter.onSuccess(result);
        }), result -> emitter.onComplete());
    });
}
项目:getLastLocationUsingGPS-android    文件:MapsActivity.java   
/**
 * Uses a {@link com.google.android.gms.location.LocationSettingsRequest.Builder} to build
 * a {@link com.google.android.gms.location.LocationSettingsRequest} that is used for checking
 * if a device has the needed location settings.
 */

protected void buildLocationSettingsRequest() {
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
    builder.addLocationRequest(mLocationRequest);
    mLocationSettingsRequest = builder.build();
}
项目:androidclient    文件:PositionGoogleFragment.java   
private void requestLocation(int accuracy) {
    // this will be our location request
    mLocationRequest = LocationRequest.create()
        .setPriority(accuracy)
        .setInterval(UPDATE_INTERVAL)
        .setFastestInterval(FASTEST_INTERVAL);

    // check for location settings now
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
        .addLocationRequest(mLocationRequest);
    PendingResult<LocationSettingsResult> pendingResult = LocationServices
        .SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
    pendingResult.setResultCallback(this);
}
项目:androidclient    文件:SendPositionGoogleFragment.java   
private void requestLocation(int accuracy) {
    // this will be our location request
    mLocationRequest = LocationRequest.create()
        .setPriority(accuracy)
        .setInterval(UPDATE_INTERVAL)
        .setFastestInterval(FASTEST_INTERVAL);

    // check for location settings now
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
        .addLocationRequest(mLocationRequest);
    PendingResult<LocationSettingsResult> pendingResult = LocationServices
        .SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
    pendingResult.setResultCallback(this);
}
项目:tiempobus    文件:MapasActivity.java   
protected void buildLocationSettingsRequest() {
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();

    mLocationRequest = REQUEST;

    builder.addLocationRequest(mLocationRequest);
    mLocationSettingsRequest = builder.build();
}