title: Force Android SDK LocationManager to provide the current location
body: <p>I'm having problems with the LocationManager not providing a last known location and not updating the location.
  The code has worked and still works under certain conditions. In short I do the following and yes, I have all the permissions set up and GPS and WLAN are activated.</p>
  
  <pre><code>LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
      try {
          locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
      } catch(SecurityException e ) {
          Log.d("GPS", "Security Exception: " + e.getLocalizedMessage());
      }
  }
  if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
      try {
          locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
      } catch(SecurityException e ) {
          Log.d("GPS", "Security Exception: " + e.getLocalizedMessage());
      }
  }
  if (locationManager.isProviderEnabled(LocationManager.PASSIVE_PROVIDER)) {
      try {
          locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, locationListener);
      } catch(SecurityException e ) {
          Log.d("GPS", "Security Exception: " + e.getLocalizedMessage());
      }
  }
  </code></pre>
  
  <p>The <code>locationListener</code> is a simple implementation of the <code>LocationListener</code> interface and just stores the provided location from <code>onLocationChanged(Location location)</code> and prints it out via <code>Log.d("GPS", location.getProvider()+" "+location.toString());</code>for debugging purposes.</p>
  
  <p>If the phone does not use GPS for quite a while (I haven't found out how much time exactly has to pass) it will not provide a location via <code>locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)</code> (it will return <code>null</code> and it will not call my <code>locationListener</code>. I've waited about 30 minutes but nothing has been updated.</p>
  
  <p>On the other hand, when I open Google Maps (e.g. in browser) I will get an immediate location and when I open my app now I will also get a location update.</p>
  
  <p>So how do other apps force Android to provide a new location?</p>
  
  <p>Any help would be appreciated.</p>