I am using Location Service in my app as follows:
LocationManager locM = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_HIGH);
criteria.setSpeedRequired(false);
String currentProvider = locM.getBestProvider(criteria, true);
Log.d("Location", "currentProvider: " + currentProvider);
Location currentLocation = locM.getLastKnownLocation(currentProvider);
if(currentLocation == null){
locM.requestLocationUpdates(currentProvider, 0, 0, locationListener);
}
And I add permissions of network and locations in Manifest.xml.
When I test this code in my Android phone earlier today, this line String currentProvider = locM.getBestProvider(criteria, true);
always returned null. After some googling, I find out that this is caused by the settings of my phone. I should turn settings->location->use wireless networks on.
I am curious that why other app(e.g. google maps) can work well even when I turn this off. Because I never modify the settings of location before, and all other apps using location service in my phone works well. Is there some way to modify settings in code?