title: How to get current location in android app?
body: <p>First I apologize for the duplication, I know this question was asked and I tried to follow up the existing answers, but it wont work. So if you can please see my code and say what is wrong or missing, that would help me a lot.</p>
  
  <p>Here's the activity, it uses only the Log (no GUI).</p>
  
  <pre><code>import android.app.Activity;
  import android.location.Location;
  import android.location.LocationListener;
  import android.location.LocationManager;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.Menu;
  
  public class MainActivity extends Activity implements LocationListener {
  
      private LocationManager lManager;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          lManager = (LocationManager) getSystemService(LOCATION_SERVICE);
          if (lManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
              lManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
                      0, 0, this);
          else
              Log.i("Test", "network provider unavailable");
  
          Location lastKnownLocation =
                  lManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
  
          if (lastKnownLocation != null) {
              Log.i("Test", lastKnownLocation.getLatitude() + ", "
                      + lastKnownLocation.getLongitude());
              lManager.removeUpdates(this);
          } else
              Log.i("Test", "null");
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.activity_main, menu);
          return true;
      }
  
      public void onLocationChanged(Location location) {
          Log.i("Test", "location changed: " + location.getLatitude() + ", "
                  + location.getLongitude());
      }
  
      public void onProviderDisabled(String provider) {
      }
  
      public void onProviderEnabled(String provider) {
      }
  
      public void onStatusChanged(String provider, int status, Bundle extras) {
      }
  }
  </code></pre>
  
  <p>when I try to run the app everything seems to work but latitude and longitude wont show on the log. I am using a real device with network location on for testing.</p>