I am trying to understand how to request Runtime Permissions in android for "Dangerous permissions" like Location.
What i understand is that the code should go like this
public void checkPermission(){
if (ActivityCompat.checkSelfPermission(..) == PackageManager.PERMISSION_GRANTED){
getLocation();
} else {
ActivityCompat.requestPermissions(..);
}
}
public void onRequestPermissionsResult(..){
switch (requestCode) {
case MY_PERMISSIONS_REQUEST: {
if (..) {
// permission was granted, yay!
getLocation();
} else {
// permission denied, boo!
}
return;
}
}
}
public Location getLocation(){
locationManager.requestLocationUpdates(..)
..
}
The thing is, this code gives me error on locationManager
telling me i have to request the location permission
So what is the proplem with this sequence?