title: Request runtime permissions on android
body: <p>I am trying to get runtime permissions on my app. However the app is not displaying the dialog to request the specific permission. The code below only works when the GPS is turned on on the phone manually.
  I am running the app on Android 5.0.</p>
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      btn_location = findViewById(R.id.get_location);
      txt_latitude = findViewById(R.id.latitude);
      txt_longitude = findViewById(R.id.longitude);
      txt_timestamp = findViewById(R.id.timestamp);
      btn_map = findViewById(R.id.map);
      mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
  
      btn_location.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              getLocation();
          }
      });
  
  }
  
  private void getLocation() {
      if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
          ActivityCompat.requestPermissions(this, new String[] {
              Manifest.permission.ACCESS_FINE_LOCATION
          }, REQUEST_LOCATION_PERMISSION);
      } else {
          mFusedLocationClient.getLastLocation().addOnSuccessListener(new OnSuccessListener &lt; Location &gt; () {
  
              @Override
              public void onSuccess(Location location) {
                  if (location != null) {
                      mLastLocation = location;
                      txt_latitude.setText(getString(R.string.location_latitude, mLastLocation.getLatitude()));
                      txt_longitude.setText(getString(R.string.location_longitude, mLastLocation.getLongitude()));
                      txt_timestamp.setText(getString(R.string.timestamp, mLastLocation.getTime()));
                  } else {
                      txt_latitude.setText(R.string.no_latitude);
                      txt_longitude.setText(R.string.no_longitude);
                      txt_timestamp.setText(R.string.no_timestamp);
  
                  }
              }
          });
      }
  }
  
  @Override
  public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
      if (requestCode == REQUEST_LOCATION_PERMISSION) {
          if (grantResults.length &gt; 0 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {
              getLocation();
          } else {
              Toast.makeText(this, R.string.location_permission_denied, Toast.LENGTH_SHORT).show();
          }
      }
  }
  }
  </code></pre>