After requesting permission, the ActivityCompat.OnRequestPermissionsResultCallback sometimes contains multiple grantResults, is it safe to just check the first one?
The shortest way you can make sure all the permissions are granted by the user.
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (Arrays.binarySearch(grantResults, -1) >= 0) {
/* Some permissions are not granted
request permission again if required */
return;
}
}
The integer array that you can use to validate permissions :
if (Arrays.binarySearch(grantResults, -1) >= 0) { // some permissions are not granted }