问题
I need to retrieve user's location by 3G or WIFI.
This is what I'm trying to do:
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
manageLocation(location);
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
public void onProviderEnabled(String provider) {
}
public void onProviderDisabled(String provider) {
}
};
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
The problem is that the only callback that is called is onProviderDisabled giving LocationManager.NETWORK_PROVIDER as parameter.
I've got that permission in the manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
How can I enable that type of location in my application?
回答1:
The user needs to go into the device's Settings app and enable location providers. You cannot enable that yourself directly.
来源:https://stackoverflow.com/questions/37440189/locationmanager-gives-network-provider-disabled