The following code always print false
this.locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Log.d(TAG, "network provider enabled: " + locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER));
The permissions have been required include:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
In Settings
, all the location switches has been turned to allowed.
Then, why is the network provider unavailable?
Update: The same code prints true on a Samsung Galaxy device, a Google Nexus device(Nexus 4) and a Lenovo device, but false on a Motorola Droid device(Droid Boinic with CM11) and a Sony device. In "Settings", all the location switches have been turned to allowed on those devices. Seems like device or OS issue.