This is My Code
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case 1: {
// If request is cancelled, the result arrays are empty.
TrackGPS gps = new TrackGPS(this, DashboardActivity.this);
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// if (ActivityCompat.shouldShowRequestPermissionRationale(this,Manifest.permission.ACCESS_FINE_LOCATION)){
//
// Toast.makeText(this,"GPS permission allows us to access location data. Please allow in App Settings for additional functionality.",Toast.LENGTH_LONG).show();
//
// }
if (gps.canGetLocation()) {
double latitude = gps.getLatitude();
double logitude = gps.getLongitude();
System.out.println("latitude=" + latitude);
System.out.println("logitude=" + logitude);
city = getCity(latitude, logitude);
tvCity.setText(city);
}
}
}
}
}
}
Permission related problem for tracking location via GPS.How to request for permission when using a higher version devices like Marshmallow.