1

I have a legacy app which, in a certain activity, requires user location. This location doesn't need to be precise, so my criteria is

Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
String provider = mLocationManager.getBestProvider(criteria, true);

which retuns network provider in general. At some point, I call getLastKnownLocation(provider) with this provider.

Everything works fine. When I switch to settings and turn off location and switch back to app, my provider becomes "passive".

So I just need the last location since precision is not that important, I continue and call getLastKnownLocation(provider).

On API 19 -> getLastKnownLocation("passive") returns a Location object. This object's provider is network, also lat / long values confirms this is the location it most recently acquired.

On API 21+ -> getLastKnownLocation("passive") returns null.

I'm %100 positive I have a location before switching and turning off location service. I've gone through documentation / diff of LocationManager but couldn't find any info regarding this.

Is there any info / doc about why would it be behaving this way on 21+ ?

Mel
  • 1,730
  • 17
  • 33

0 Answers0