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)); }
@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; } }
@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); }
@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; } }
@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)); }
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); }
/** * Check whether gps is turned on or not. */ public boolean checkLocationSettings() { // In case of a test session don't check settings if (((AppRunnest) activity.getApplication()).isTestSession()) { return true; } if (!gpsIsTurnedOn) { PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings( googleApiClient, locationSettingsRequest); result.setResultCallback(this); } return gpsIsTurnedOn; }
@Override public void onResult(@NonNull LocationSettingsResult r) { switch (r.getStatus().getStatusCode()) { case LocationSettingsStatusCodes.SUCCESS: gpsIsTurnedOn = true; break; case LocationSettingsStatusCodes.RESOLUTION_REQUIRED: try { r.getStatus().startResolutionForResult(activity, SideBarActivity.REQUEST_CHECK_SETTINGS); } catch (IntentSender.SendIntentException ignored) { ignored.printStackTrace(); } break; case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE: gpsIsTurnedOn = false; break; } }
/** * 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(); } } } }); }
@Override public void onResult(@NonNull LocationSettingsResult locationSettingsResult) { final Status status = locationSettingsResult.getStatus(); switch (status.getStatusCode()) { case LocationSettingsStatusCodes.SUCCESS: startLocationUpdates(); break; case LocationSettingsStatusCodes.RESOLUTION_REQUIRED: try { status.startResolutionForResult(LocationActivity.this, REQUEST_CHECK_LOCATION_SETTINGS); } catch (IntentSender.SendIntentException e) { e.printStackTrace(); 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; } }
@Override public void onResult(@NonNull LocationSettingsResult result) { final Status status = result.getStatus(); switch (status.getStatusCode()) { case LocationSettingsStatusCodes.SUCCESS: mLocationActivityListener.onSettingsCheckSuccess(); break; case LocationSettingsStatusCodes.RESOLUTION_REQUIRED: try { startResolvingSettingsProblem(status); } catch (IntentSender.SendIntentException e) { mLocationActivityListener.onSettingsCheckFailure(); } break; default: mLocationActivityListener.onSettingsCheckFailure(); break; } }
@Override public void onResult(LocationSettingsResult result) { Status status = result.getStatus(); switch (status.getStatusCode()) { case LocationSettingsStatusCodes.SUCCESS: wasSending = JappPreferences.isUpdatingLocationToServer(); if (!wasSending) { showLocationNotification("Japp verzendt je locatie niet!", Color.rgb(244, 66, 66)); } else { showLocationNotification("Japp verzendt je locatie", Color.rgb(113, 244, 66)); } break; case LocationSettingsStatusCodes.RESOLUTION_REQUIRED: if(listener != null) { listener.onResolutionRequired(status); } break; } }
@Override public void onResult(LocationSettingsResult result) { final Status status = result.getStatus(); switch (status.getStatusCode()) { case LocationSettingsStatusCodes.SUCCESS: // All location settings are satisfied. The client can // initialize location requests here. startLocationUpdates(); break; case LocationSettingsStatusCodes.RESOLUTION_REQUIRED: // Location settings are not satisfied, but this can be fixed // by showing the user a dialog. 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; } }
public boolean onTransact(int paramInt1, Parcel paramParcel1, Parcel paramParcel2, int paramInt2) { switch (paramInt1) { default: return super.onTransact(paramInt1, paramParcel1, paramParcel2, paramInt2); case 1598968902: paramParcel2.writeString("com.google.android.gms.location.internal.ISettingsCallbacks"); return true; } paramParcel1.enforceInterface("com.google.android.gms.location.internal.ISettingsCallbacks"); if (paramParcel1.readInt() != 0) {} for (LocationSettingsResult localLocationSettingsResult = (LocationSettingsResult)LocationSettingsResult.CREATOR.createFromParcel(paramParcel1);; localLocationSettingsResult = null) { a(localLocationSettingsResult); paramParcel2.writeNoException(); return true; } }
@Override public void onResult(LocationSettingsResult locationSettingsResult) { final Status status = locationSettingsResult.getStatus(); switch (status.getStatusCode()) { case LocationSettingsStatusCodes.SUCCESS: Log.i(LOG_TAG, "All location settings are satisfied."); startLocationUpdates(); break; case LocationSettingsStatusCodes.RESOLUTION_REQUIRED: Log.i(LOG_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(MainActivity.this, REQUEST_CHECK_SETTINGS); } catch (IntentSender.SendIntentException e) { Log.i(LOG_TAG, "PendingIntent unable to execute request."); } break; case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE: Log.i(LOG_TAG, "Location settings are inadequate, and cannot be fixed here. Dialog " + "not created."); break; } }
@Override public void onResult(LocationSettingsResult locationSettingsResult) { final Status status = locationSettingsResult.getStatus(); switch (status.getStatusCode()) { case LocationSettingsStatusCodes.SUCCESS: Log.i(TAG, "All location settings are satisfied."); GetLastLocation(); 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(mActivity, REQUEST_CHECK_SETTINGS); } catch (IntentSender.SendIntentException e) { ErrorHappened("PendingIntent unable to execute request."); } break; case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE: ErrorHappened("Location settings are inadequate, and cannot be fixed here. Dialog " + "not created."); break; } }
public void checkLocationEnabled() { if (isLocationEnabled()) { doJob(); return; } // If location isn't enabled - check whether we can call Google Play Services or user to manually // switch Location final int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity.getApplicationContext()); if (status == ConnectionResult.SUCCESS) { PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings( mGoogleApiClient, mLocationSettingsRequest ); result.setResultCallback(this); } else { // If no services available - the only thing we can do is to // ask user to switch Location manually activity.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); waitForResume = true; } }
public void checkLocationSettings() { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Request missing location permission. ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_CODE_LOCATION); } else { // Location permission has been granted, continue as usual. PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, mLocationSettingsRequest); result.setResultCallback(this); } }
/** * 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)); } }); }
@Override protected void onGoogleApiClientReady(GoogleApiClient apiClient, SingleEmitter<LocationSettingsResult> emitter) { setupLocationPendingResult( LocationServices.SettingsApi.checkLocationSettings(apiClient, locationSettingsRequest), SingleResultCallBack.get(emitter) ); }
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(); }
@Override @SuppressWarnings({"MissingPermission"}) public void onResult(@NonNull LocationSettingsResult locationSettingsResult) { int statusCode = locationSettingsResult.getStatus().getStatusCode(); if (statusCode == LocationSettingsStatusCodes.SUCCESS) { PendingResult<Status> result = LocationServices.FusedLocationApi.requestLocationUpdates(playServices, locationRequest, this); result.setResultCallback(new ResultCallback<Status>() { @Override public void onResult(Status status) { if (status.isSuccess()) { Toast.makeText(getApplicationContext(), "Pedido esta na fila", Toast.LENGTH_LONG).show(); } else { Toast.makeText(getApplicationContext(), "Erro ao solicitar location! "+status.getStatusMessage(), Toast.LENGTH_LONG).show(); finish(); } } }); } else if (statusCode == LocationSettingsStatusCodes.RESOLUTION_REQUIRED) { //obter permissao para usar location } else { Toast.makeText(this, "Algum problema ao tentar obter location", Toast.LENGTH_LONG).show(); finish(); } }
private void checkLocationEnabled() { LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder() .addLocationRequest(_locationRequest); PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(_client, builder.build()); result.setResultCallback(new MyLocationSettingsCallback()); }
@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()); } }); }
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); } }
@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; } } }); }
public void requestLocationUpdates() { Log.d(TAG, "requestLocationUpdates()"); LocationServices.SettingsApi.checkLocationSettings(googleApiClient, locationSettingsRequest).setResultCallback(new ResultCallback<LocationSettingsResult>() { @Override public void onResult(@NonNull LocationSettingsResult locationSettingsResult) { final Status status = locationSettingsResult.getStatus(); switch (status.getStatusCode()) { case LocationSettingsStatusCodes.SUCCESS: Log.d(TAG, "All location settings are satisfied."); startService(new Intent(getApplicationContext(), LocationService.class)); // Expliciting Ignoring this warning, handling it just with a Try-Catch try { LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, LocationService.this); } catch (SecurityException e) { Log.e(TAG, "SecurityException: " + e); } break; case LocationSettingsStatusCodes.RESOLUTION_REQUIRED: Log.e(TAG, "RESOLUTION_REQUIRED"); // Notify anyone listening for Resolution Broadcasts about the problem to fix. Intent intent = new Intent(ACTION_RESOLUTION); intent.putExtra(EXTRA_STATUS, status); LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent); break; case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE: Log.e(TAG, "SETTINGS_CHANGE_UNAVAILABLE"); break; } } }); }
/** * 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; } } }); }
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(); } } }); }
protected void checkLocationSettings() { PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings( googleApiClient, locationSettingsRequest ); result.setResultCallback(this); }
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; } } }); }
@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); }
public void checkLocationSettings() { LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder() .addLocationRequest(request); PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(client, builder.build()); result.setResultCallback(this); }
public void startLocationUpdates() { LocationServices.SettingsApi.checkLocationSettings( mGoogleClient, mLocationSettingsRequest ).setResultCallback(new ResultCallback<LocationSettingsResult>() { @Override public void onResult(@NonNull LocationSettingsResult locationSettingsResult) { final Status status = locationSettingsResult.getStatus(); switch (status.getStatusCode()) { case LocationSettingsStatusCodes.SUCCESS: requestLocation(); break; case LocationSettingsStatusCodes.RESOLUTION_REQUIRED: try { // Show the dialog by calling startResolutionForResult(), and check the // result in onActivityResult(). status.startResolutionForResult( activity, REQUEST_CHECK_SETTINGS); } catch (IntentSender.SendIntentException ignored) {} break; case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE: Toast.makeText(activity, R.string.string_location_settings_inadequate, Toast.LENGTH_LONG).show(); } } }); }
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; } } }); }
/** * Check if the device's location settings are adequate for the app's needs using the * {@link com.google.android.gms.location.SettingsApi#checkLocationSettings(GoogleApiClient, * LocationSettingsRequest)} method, with the results provided through a {@code PendingResult}. */ protected void checkLocationSettings() { PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings( apiClient, locationSettingsRequest ); result.setResultCallback(this); }
/** * The callback invoked when * {@link com.google.android.gms.location.SettingsApi#checkLocationSettings(GoogleApiClient, * LocationSettingsRequest)} is called. Examines the * {@link com.google.android.gms.location.LocationSettingsResult} object and determines if * location settings are adequate. If they are not, begins the process of presenting a location * settings dialog to the user. */ @Override public void onResult(LocationSettingsResult locationSettingsResult) { final Status status = locationSettingsResult.getStatus(); switch (status.getStatusCode()) { case LocationSettingsStatusCodes.SUCCESS: Log.i(this.getLocalClassName(), "All location settings are satisfied."); // startLocationUpdates(); requestingLocationUpdates = true; break; case LocationSettingsStatusCodes.RESOLUTION_REQUIRED: Log.i(this.getLocalClassName(), "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(TabbedListActivity.this, REQUEST_CHECK_SETTINGS); } catch (IntentSender.SendIntentException e) { //TODO Log.i(this.getLocalClassName(), "PendingIntent unable to execute request."); } break; case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE: //TODO Log.i(this.getLocalClassName(), "Location settings are inadequate, and cannot be fixed here. Dialog " + "not created."); break; } }
/** * Check if the device's location settings are adequate for the app's needs using the * {@link com.google.android.gms.location.SettingsApi#checkLocationSettings(GoogleApiClient, * LocationSettingsRequest)} method, with the results provided through a {@code PendingResult}. */ protected void checkLocationSettings() { Log.i(this.getLocalClassName(), "Checking location settings."); PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings( apiClient, locationSettingsRequest ); result.setResultCallback(this); }
@Override public void onResult(LocationSettingsResult locationSettingsResult) { final Status status = locationSettingsResult.getStatus(); switch (status.getStatusCode()) { case LocationSettingsStatusCodes.SUCCESS: logger.d("All location settings are satisfied."); fulfilledCheckLocationSettings = true; startUpdating(locationRequest); break; case LocationSettingsStatusCodes.RESOLUTION_REQUIRED: logger.w("Location settings are not satisfied. Show the user a dialog to" + "upgrade location settings. You should hook into the Activity onActivityResult and call this provider onActivityResult method for continuing this call flow. "); if (context instanceof Activity) { try { // Show the dialog by calling startResolutionForResult(), and check the result // in onActivityResult(). status.startResolutionForResult((Activity) context, REQUEST_CHECK_SETTINGS); } catch (IntentSender.SendIntentException e) { logger.i("PendingIntent unable to execute request."); } } else { logger.w("Provided context is not the context of an activity, therefore we cant launch the resolution activity."); } break; case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE: logger.i("Location settings are inadequate, and cannot be fixed here. Dialog " + "not created."); stop(); break; } }