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

The following examples show how to use com.google.android.gms.location.LocationSettingsStates. 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: WhereAmIActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode,
                                int resultCode,Intent data){
  final LocationSettingsStates states = LocationSettingsStates.fromIntent(data);

  if (requestCode == REQUEST_CHECK_SETTINGS) {
    switch (resultCode) {
      case Activity.RESULT_OK:
        // Requested changes made, request location updates.
        requestLocationUpdates();
        break;
      case Activity.RESULT_CANCELED:
        // Requested changes were NOT made.
        Log.d(TAG, "Requested settings changes declined by user.");
        // Check if any location services are available, and if so
        // request location updates.
        if (states.isLocationUsable())
          requestLocationUpdates();
        else
          Log.d(TAG, "No location services available.");
        break;
      default: break;
    }
  }
}
 
Example #2
Source File: LocationActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){

  final LocationSettingsStates states = LocationSettingsStates.fromIntent(data);

  if (requestCode == REQUEST_CHECK_SETTINGS) {
    switch (resultCode) {
      case Activity.RESULT_OK:
        // TODO Changes were applied.
        break;
      case Activity.RESULT_CANCELED:
        // TODO Changes were not applied.
        // TODO Check states to confirm if we can attempt
        // TODO to request location updates anyway.
        break;
      default: break;
    }
  }
}
 
Example #3
Source File: WhereAmIActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode,
                                int resultCode,Intent data){
  final LocationSettingsStates states = LocationSettingsStates.fromIntent(data);

  if (requestCode == REQUEST_CHECK_SETTINGS) {
    switch (resultCode) {
      case Activity.RESULT_OK:
        // Requested changes made, request location updates.
        requestLocationUpdates();
        break;
      case Activity.RESULT_CANCELED:
        // Requested changes were NOT made.
        Log.d(TAG, "Requested settings changes declined by user.");
        // Check if any location services are available, and if so
        // request location updates.
        if (states.isLocationUsable())
          requestLocationUpdates();
        else
          Log.d(TAG, "No location services available.");
        break;
      default: break;
    }
  }
}
 
Example #4
Source File: WhereAmIActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode,
                                int resultCode,Intent data){
  final LocationSettingsStates states = LocationSettingsStates.fromIntent(data);

  if (requestCode == REQUEST_CHECK_SETTINGS) {
    switch (resultCode) {
      case Activity.RESULT_OK:
        // Requested changes made, request location updates.
        requestLocationUpdates();
        break;
      case Activity.RESULT_CANCELED:
        // Requested changes were NOT made.
        Log.d(TAG, "Requested settings changes declined by user.");
        // Check if any location services are available, and if so
        // request location updates.
        if (states.isLocationUsable())
          requestLocationUpdates();
        else
          Log.d(TAG, "No location services available.");
        break;
      default: break;
    }
  }
}
 
Example #5
Source File: WhereAmIActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode,
                                int resultCode,Intent data){
  final LocationSettingsStates states = LocationSettingsStates.fromIntent(data);

  if (requestCode == REQUEST_CHECK_SETTINGS) {
    switch (resultCode) {
      case Activity.RESULT_OK:
        // Requested changes made, request location updates.
        requestLocationUpdates();
        break;
      case Activity.RESULT_CANCELED:
        // Requested changes were NOT made.
        Log.d(TAG, "Requested settings changes declined by user.");
        // Check if any location services are available, and if so
        // request location updates.
        if (states.isLocationUsable())
          requestLocationUpdates();
        else
          Log.d(TAG, "No location services available.");
        break;
      default: break;
    }
  }
}
 
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: 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));
}