title: Cannot get current location
body: <p>I need to get current device location (lat/lng) but "getCurrentLocation()" shows "No provider" all the time so location is null. I call this method in onCreate() and declared all permissions in Manifest file:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  </code></pre>
  
  <p>Location services on real device are enabled as well.</p>
  
  <p>getCurrentLocation() java code:</p>
  
  <pre><code>    public void getCurrentLocation() {
      locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
      Criteria c = new Criteria();
      provider = locationManager.getBestProvider(c, false);
      if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &amp;&amp; ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
          // TODO: Consider calling
          //    ActivityCompat#requestPermissions
          // here to request the missing permissions, and then overriding
          //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
          //                                          int[] grantResults)
          // to handle the case where the user grants the permission. See the documentation
          // for ActivityCompat#requestPermissions for more details.
          return;
      }
      location = locationManager.getLastKnownLocation(provider);
      if(location!=null)
      {
          double lng=location.getLongitude();
          double lat=location.getLatitude();
          Toast.makeText(this, Double.toString(lat) + "\n" + Double.toString(lng), Toast.LENGTH_SHORT).show();
      }
      else
      {
          Toast.makeText(this, "No provider", Toast.LENGTH_SHORT).show();
      }
  }
  </code></pre>
  
  <p>How can I fix it?</p>
  
  <p>P.S.: I revised a lot of similar questions but can't find suitable solution.</p>