I only need the last known gps location from any provider
without telling any provider to update.
Is this possible without adding listeners or requestLocationUpdates?
The thing is i need only an approximate position without blocking delay
Im trying this code from an Activity onCreate but the providers.size() is always zero
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
List<String> providers = lm.getProviders(true);
Location l = null;
for (int i=providers.size()-1; i>=0; i--) {
l = lm.getLastKnownLocation(providers.get(i));
if (l != null)
break;
}
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permisssion.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permisssion.ACCESS_COARSE_LOCATION"></uses-permission>
Try this code snippet.