I have some getLastKnowLocation code that has worked for years, but it does not work on the Samsung Galaxy S3 4.0.4.
Location location = null;
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
// The S3 returns null here (even though location is enabled), google maps works.
try {
location = locationManager.getLastKnownLocation(provider);
} catch (IllegalArgumentException e) {
}
if ( location == null ) { // only S3 gets this....
location = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
}
I have noticed that if I add PASSIVE_PROVIDER, I do get an location, but I never get any onLocationChanged. The same code works on all system I have tested from 2.1 - 4.1 (except my CM10 which seems even more confused)
Any ideas on what is going on? Bug/Feature?
I found others with similar problems No GPS location updates on Galaxy S3
This isn't related to Android version, i have this code working on a Galaxy Nexus 4.2.2 and not on S3 4.1 nor Sony XPeria S 4.0.4
i am doubting the GPS location is not detecting you (this require time and good GPS signal), in my app when i found that GPS is not reponding or not enabled i switch to network detection (~45Metres of precision is not that bad for my case where i have to search for devices on a radius of 10 Km)
I upgraded the phone to 4.1 and the bug/feature disappeared.