I have recently updated the code for an Android app to request permissions on Android 6.0+. However, I am now facing a dilemma on how I want to check for permissions.
I saw people online checking the OS version before checking for permissions, because versions before 23, permissions are unnecessary to check due to them being granted on installation.
Right now my checks look like this,
if(checkPermissions()){
doThings();
} else {
requestPermissions();
}
but should I take the effort to add this?
if (Build.VERSION.SDK_INT >= 23) {
if(checkPermissions()){
doThings();
} else {
requestPermissions();
}
} else {
doThings();
}
I don't see the point of adding the latter to the code as from my understanding, older versions of android could run into the first sample code just fine.
All this brings me to ask, is there a benefit to checking Android version in this case?
but should I take the effort to add this?
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if(checkPermissions()){ doThings(); } else { requestPermissions(); } } else { doThings(); }
You should if checkPermissions()
, and requestPermissions()
invokes classes or methods strictly API 23 or later. Or else, you may do as you wish.
All this brings me to ask, is there a benefit to checking Android version in this case?
As far as I know, the verification by itself isn't necessary, given what I said above. So this check is just an expendable if
clause cluttering your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With