status.startResolutionForResult(LocationByGPS.this, REQUEST_CHECK_SETTINGS);
status.startResolutionForResult( getActivity(), 1000); } catch (IntentSender.SendIntentException e) {
status.startResolutionForResult( MainActivity.this, REQUEST_LOCATION);
status.startResolutionForResult( getActivity(), REQUEST_LOCATION);
status.startResolutionForResult(Login.this, 1000); } catch (IntentSender.SendIntentException e) {
status.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS); } catch (IntentSender.SendIntentException e) {
status.startResolutionForResult( MapActivity.this, REQUEST_CHECK_SETTINGS);
status.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS); } catch (IntentSender.SendIntentException e) { Log.i(TAG, "PendingIntent unable to execute request.");
status.startResolutionForResult( activity, 1000); } catch (IntentSender.SendIntentException e) {
LocationSettingsStates locationSettingsStates = locationSettingsResult.getLocationSettingsStates(); if (!locationSettingsStates.isGpsPresent() || !locationSettingsStates.isGpsUsable()) { Status status = locationSettingsResult.getStatus(); if (status.getStatusCode() == LocationSettingsStatusCodes.RESOLUTION_REQUIRED) { try { status.startResolutionForResult(StilActivity.this, REQUEST_CHECK_SETTINGS); } catch (IntentSender.SendIntentException th) { Log.e(TAG, "Error opening settings activity.", th); } } }
@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."); startLocationUpdates(); 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(MainActivity.this, 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; } } // This code is from https://github.com/googlesamples/android-play-location/blob/master/LocationSettings/app/src/main/java/com/google/android/gms/location/sample/locationsettings/MainActivity.java
request = LocationRequest.create(); LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(request); builder.setAlwaysShow(true); PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(apiClient, builder.build()); result.setResultCallback(new ResultCallback<LocationSettingsResult>() { @Override public void onResult(@NonNull LocationSettingsResult result) { final Status status = result.getStatus(); switch (status.getStatusCode()) { case LocationSettingsStatusCodes.SUCCESS: LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, request, locationListener); break; case LocationSettingsStatusCodes.RESOLUTION_REQUIRED: try { status.startResolutionForResult(context, REQUEST_CODE); } catch (IntentSender.SendIntentException e) {} break; case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE: break; } } });
public void requestLocationAccess(){ if(mLocationRequest == null) createLocationRequest(); final LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(mLocationRequest); builder.setAlwaysShow(true); //this is the key ingredient com.google.android.gms.common.api.PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build()); result.setResultCallback(new ResultCallback<LocationSettingsResult>(){ @Override public void onResult(@NonNull LocationSettingsResult result){ final Status resultStatus = result.getStatus(); switch(resultStatus.getStatusCode()){ case LocationSettingsStatusCodes.SUCCESS: // All location settings are satisfied. isLocationEnabled = true; getLastKnownLocationIfReady(); break; case LocationSettingsStatusCodes.RESOLUTION_REQUIRED: // Location settings are not satisfied. But could be fixed by showing the user a dialog. You need to override OnActivityResult if you want to handle the user's interaction with the dialog. resultStatus.startResolutionForResult(this, REQUEST_LOCATION); break; default: break; } } }); }
status.startResolutionForResult(MainActivity.getInstance(), REQUEST_CHECK_SETTINGS); } catch (IntentSender.SendIntentException e) {
"upgrade location settings "); try { status.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS); } catch (IntentSender.SendIntentException e) { Log.i(TAG, "PendingIntent unable to execute request.");
status.startResolutionForResult(getActivity(), 1000); } catch (IntentSender.SendIntentException ignored) {} break;
status.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS); } catch (IntentSender.SendIntentException e) { Log.i(TAG, "PendingIntent unable to execute request.");
ResultCallback<LocationSettingsResult> locationSettingsResultCallback = new ResultCallback<LocationSettingsResult>() { @Override public void onResult(LocationSettingsResult result) { final Status status = result.getStatus(); final LocationSettingsStates state = result.getLocationSettingsStates(); 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 could be fixed by showing the user // a dialog. try { // Show the dialog by calling startResolutionForResult(), // and check the result in onActivityResult(). status.startResolutionForResult( PickupLocationActivity.this, 1000); } 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; } } };
status.startResolutionForResult(getActivity(), MainActivity.REQUEST_CHECK_SETTINGS); } catch (IntentSender.SendIntentException e) {
resultStatus.startResolutionForResult(this, REQUEST_LOCATION); break; }catch(IntentSender.SendIntentException ignored){}