4

I am trying to make use of android fused location provider to get the device location every 30 minutes using PRIORITY_HIGH_ACCURACY. What is surprising to me is that,

When GPS is disabled, I am expecting the API to make use of network provider and sensors to give me location with little bad accuracy. However, location returned by the API in this case is null for Android 5.0.

This behavior is different in Android 4.0, it gives me location with little bad accuracy as expected. I cannot find any documentation on this! Any thoughts??

EDIT: Just realized that, Device having Android 5.0 do not have a SIM, does this mean that if there is no SIM, fused location provider will not consider WiFi either to find best location?

Kaps
  • 2,345
  • 2
  • 26
  • 37

1 Answers1

0

Cache will be cleared after device location is closed so you should use LocationRequest with PRIORITY_HIGH_ACCURACY. You can use LocationCallBack as a weak reference so you can escape from memory leak. You must remove location updates in onStop(). Code like that,

            LocationRequest locationRequest = LocationRequest.create();
            locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
            locationRequest.setInterval(2000);
            LocationCallback locationCallback = new LocationCallback() {
                @Override
                public void onLocationResult(LocationResult locationResult) {
                    super.onLocationResult(locationResult);
                    if (locationResult == null || locationResult.getLastLocation() == null)
                        return;
                    updateLocation(locationResult.getLastLocation());
                }
            };

            fusedLocationProviderClient.requestLocationUpdates(locationRequest, locationCallback, null);
buraktemzc
  • 390
  • 1
  • 6
  • 19