Reputation: 554
In my app, i have used requestSingleUpdate() method it's working well in all devices but in some devices 2.3 android OS version, GPS is not getting locations. Here is the code,
Intent intentp = new Intent(context, MyLocationReceiver.class);
pendingIntent = PendingIntent.getBroadcast(context, 0, intentp,PendingIntent.FLAG_UPDATE_CURRENT);
criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
provider = locationManager.getBestProvider(criteria, true);
if(provider != null)
{
locationManager.requestSingleUpdate(provider, pendingIntent);
}
Why requestSingleUpdate() method with GPS provider is not working in some devices? Specifically not working in 2.3.6 OS version GT - S5830 model Samsung device and MicroMax A57.
Upvotes: 1
Views: 5041
Reputation: 8921
criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
provider = locationManager.getBestProvider(criteria, true);
if(provider != null)
{
locationManager.requestSingleUpdate(provider, pendingIntent);
}
Is asking android for the best location provider whether that be wi-fi, cell or gps. if the user doesn't have location services enabled, there will be no best provider known to the OS and so the provider will return null.
There is nothing you can do about this, it depends on the users OS settings and whether they choose make location information available to applications
--EDIT--
In your call to getBestProvider() you've asked for enabled providers only (that's the second parameter in the method call which you have set to true). If the user has disabled all providers, you will get null.
Upvotes: 1
Reputation: 17083
Prefer LocationClient over LocationManager to retrieving the current location.
It uses the Google Play Services
(available in practically 100% of the devices) it's much more powerful and usually solves many problems. Since I made the switch, I've never had any sort of location problems.
Upvotes: 1