I am using Google's FusedLocationProvider API to receive location updates 
on user's device. I am switching  between PRIORITY_HIGH_ACCURACY and 
PRIORITY_BALANCED_POWER_ACCURACY when device GPS is on/off.

//location manager for GPS events
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
//request to FusedLocationProvider API
if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
    
sendLocationRequest(createLocationRequest(LocationRequest.PRIORITY_HIGH_ACCURACY,
 interval2, fastestInterval2));
else if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
    
sendLocationRequest(createLocationRequest(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY,
 interval, fastestInterval));


The problem is when I register to receive location updates on 3G network 
and Wifi & GPS turned off, then priority being set to 
PRIORITY_BALANCED_POWER_ACCURACY, the FusedLocationProvider asks for 
RESOLUTION_REQUIRED, and it is to enable Wifi. I want to receive location 
updates on 3G network also without wifi or GPS, i.e to 100 meters block 
level accuracy as stated in the API documentation.

I am using these intervals:

private long /*BALANCED_POWER_ACCURACY*/interval=3600000, 
fastestInterval=300000, /*HIGH_ACCURACY*/interval2=10000, fastestInterval2=5000;

These are the corresponding methods:

//creating location newRequestprivate LocationRequest createLocationRequest(int 
priority, long interval, long fastestInterval){
    LocationRequest locationRequest = new LocationRequest();
    locationRequest.setInterval(interval);
    locationRequest.setFastestInterval(fastestInterval);
    locationRequest.setPriority(priority);
    return locationRequest;}
//sending location newRequest with needed quality of serviceprivate void 
sendLocationRequest(final LocationRequest locationRequest){
    LocationSettingsRequest.Builder builder = new 
LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
    PendingResult<LocationSettingsResult> result = 
LocationServices.SettingsApi.checkLocationSettings(googleApiClient, 
builder.build());
    result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
        @Override
        public void onResult(@NonNull LocationSettingsResult 
locationSettingsResult) {
            Status status = locationSettingsResult.getStatus();
            switch (status.getStatusCode()) {
                case LocationSettingsStatusCodes.SUCCESS: {
                    //requesting location updatesPendingResult<Status> 
statusPendingResult =
                            
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, 
locationRequest, CurrLocationService.this);
                    break;
                }
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                {
                    Toast.makeText(CurrLocationService.this,
                            getString(R.string.app_name)+" Error: Try using 
GPS/Wifi" + status.getStatusMessage() + " " + status.getStatus(), 
Toast.LENGTH_LONG).show();
                    stopSelf();
                    break;
                }
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                {
                    Toast.makeText(CurrLocationService.this,
                            getString(R.string.app_name)+" Error: Unable to get 
your location updates", Toast.LENGTH_SHORT).show();
                    stopSelf();
                    break;
                }
            }
        }
    });}



-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/8b52bc2a-6542-4713-b4bc-1b547fd4178d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to