title: Getting null location in spite of checking everything
body: <p>I wish to access user's position using gps system of phone.</p>
  
  <blockquote>
    <p>In manifest I've included </p>
  </blockquote>
  
  <pre><code>&lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
  &lt;uses-feature android:name="android.hardware.location.gps" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;
  </code></pre>
  
  <blockquote>
    <p>I get null location at .appLocationService.getLocation(); </p>
  </blockquote>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  AppLocationService appLocationService;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      appLocationService = new AppLocationService(MainActivity.this);
  }
  public void OpenAddress(View v) {
      appLocationService =new AppLocationService(MainActivity.this);
      Location location = appLocationService.getLocation();
      if (location != null) {
          // getting co-ordinates and address
      }
      else showSettingsAlert();
    }
  }
  </code></pre>
  
  <blockquote>
    <p>I get null location at .getLastKnownLocation(provider);Here i get all locations from all providers. But all seem to return  null location </p>
  </blockquote>
  
  <pre><code>public class AppLocationService extends Service implements LocationListener {
  public AppLocationService(){}
  Context mcontext;protected LocationManager locationManager;Location location;
  private static final long MIN_DISTANCE_FOR_UPDATE = 10, MIN_TIME_FOR_UPDATE = 1000 * 60;
  public AppLocationService(Context context) {
      locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
      mcontext=context;
  }
  public Location getLocation() {
      boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
      if (!isGPSEnabled) //enabling it    
      else {
          if (locationManager != null) {
              locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_FOR_UPDATE, MIN_DISTANCE_FOR_UPDATE, this);
              List&lt;String&gt; providers = locationManager.getProviders(true);
              Location bestLocation = null;
              for (String provider : providers) {
                  Location l = locationManager.getLastKnownLocation(provider);
                  if (l == null) continue;
                  if(bestLocation == null || l.getAccuracy() &lt; bestLocation.getAccuracy())
                      bestLocation=l;
              }
              return bestLocation;
          }
      }
      return null;
  }
  </code></pre>