android getLaskKnownLocation null
<p>I have tried both GPS and Network Provider but they give null location for getLastKnownLocation.  I do not get any onLocationChanged either.  I am trying from my apartment where the cell signal is strong.  I can even browse internet well and download and install apps fine from market.  </p>

<p>I have read few threads on same topic but their suggestion seems I already have tried.</p>

<p>Here is my code snippet.</p>

<pre><code> public void onCreate() {
    // TODO Auto-generated method stub
    super.onCreate();
    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    if(null == locationManager) {
        Log.d(TAG, "location manager NULL");
    }
    geocoder = new Geocoder(this); 

    // Initialize with the last known location
    Location lastLocation = locationManager
            .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
    if (lastLocation != null)
        onLocationChanged(lastLocation);
    else
        Log.i(TAG, "null LastKnownLocation");
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    // TODO Auto-generated method stub
    super.onStartCommand(intent, flags, startId);
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
            0,0, this);
    Log.d(TAG, "requested location updates");

    return START_STICKY;
}
</code></pre>

<p>As per log:</p>

<pre><code>mitenm@pinkydebian:/media/sf_E_DRIVE/tmp$ adb logcat LocationNotifierService:* *:S
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
I/LocationNotifierService(30866): null LastKnownLocation
D/LocationNotifierService(30866): gps provider enabled:true
D/LocationNotifierService(30866): network provider enabled:true
D/LocationNotifierService(30866): onCreate
D/LocationNotifierService(30866): requested location updates
D/LocationNotifierService(30866): requested location updates
D/LocationNotifierService(30866): requested location updates
</code></pre>

<p>I have "unlock receiver" so when I unlock my screen I request location updates which is working as expected from logs.  But the onLocationChanged method is not getting invoked.</p>

<p>I have permission added to manifest both for fine and coarse.</p>

<p>Regards,</p>

<p>Miten.</p>
