Following code having multiple permissions, My error is when ever onclick button it asking only one permission, and again i click means it asking another permission.
My Onclick
public void onClick(View v) {
getPermissionCamara();
getStroagePermission();
selectImage();
}
My permissions are like this
private static final int CAMERA_PERMISSIONS_REQUEST = 1;
private static final int STROAGE_PERMISSIONS_REQUEST = 2;
public void getPermissionCamara() {
if (ContextCompat.checkSelfPermission(this, CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
if (shouldShowRequestPermissionRationale(
CAMERA)) {
}
requestPermissions(new String[]{CAMERA},CAMERA_PERMISSIONS_REQUEST);
}
}
public void getStroagePermission() {
if (ContextCompat.checkSelfPermission(this,READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
if (shouldShowRequestPermissionRationale(
READ_EXTERNAL_STORAGE)) {
}
requestPermissions(new String[]{READ_EXTERNAL_STORAGE},STROAGE_PERMISSIONS_REQUEST);
}
}
@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String permissions[],
@NonNull int[] grantResults) {
// Make sure it's our original READ_CONTACTS request
if (requestCode == CAMERA_PERMISSIONS_REQUEST) if (grantResults.length == 1 &&
grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "Camera permission granted", Toast.LENGTH_SHORT).show();
}
else if (requestCode == STROAGE_PERMISSIONS_REQUEST) if (grantResults.length == 2 &&
grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "Read Contacts permission granted", Toast.LENGTH_SHORT).show();
}
}