Network provider not providing location updates
For network based location, they are a lot less inaccurate than GPS, meaning you need to move the device a much larger distance to allow the signal to hook on to another network tower before
onLocationChanged() is called. Also not all network towers provide location.
NETWORK_PROVIDER is not giving location updates
To ensure if the NETWORK_PROVIDER is operational check like this,
if(isLocationProviderEnabled(LocationManager.NETWORK_PROVIDER))
{
Log.i("PROVIDER", "ENABLED");
}
LocationManager.NETWORK_PROVIDER is not triggering onLocationChanged in ICS
This is known issue:
After device reboot the network location provider works fine but after some time it stops updating.
https://code.google.com/p/android/issues/detail?id=57707
Unfortunately without solution yet.
NETWORK_PROVIDER not Working in android
Instead of using the legacy LocationManager
, you should use the Google's new Fused Location API connecting to the Google Play Services, you can get the lastknown and current location, here is how to get the lastknownlocation:
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
public class MainActivity extends ActionBarActivity implements
ConnectionCallbacks, OnConnectionFailedListener {
...
@Override
public void onConnected(Bundle connectionHint) {
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
if (mLastLocation != null) {
mLatitudeText.setText(String.valueOf(mLastLocation.getLatitude()));
mLongitudeText.setText(String.valueOf(mLastLocation.getLongitude()));
}
}
}
For more details check official example here
And in your Manifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.gms.location.sample.basiclocationsample" >
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
</manifest>
Android: LocationManager service stops updating when set to NETWORK_PROVIDER
I've solved the problem by switching to the Google Play Fused Location provider. A more detailed post around this can be found here: https://stackoverflow.com/a/19282976/3532181
Sadly the standard network provider just seemed too unreliable when it came to updates, ranging from an update within 8 minutes to hours before a new update was sent to the app.
Related Topics
R.Java Disappears After Project Clean
Gesture Detection and Scrollview Issue
Xamarin Forms Android App Crashes Running Debug with VS Android Emulator
Android 4.4 Giving Err_Cache_Miss Error in Onreceivederror for Webview Back
Button in Custom Android Toast
Fused Location Provider Unexpected Behavior
Android: Subscribe to Firebase Cloud Messaging(Fcm) Topic
Android Decoder->Decode Returned False for Bitmap Download
Issues with Android Tabhost Example
Intent Putextra Arraylist<Namevaluepair>
Push Up Content When Clicking in Edit Text
How to Make Layouts for Several Android Screen Sizes
How to Check If Running on UI Thread in Android
Why Is Listview.Getcheckeditempositions() Not Returning Correct Values
How to Detect "Recent Apps" System Button Clicks (Honeycomb+)