Articles → Android → shouldShowRequestPermissionRationale method in android

shouldShowRequestPermissionRationale method in android






Purpose





Example




if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) !=
  PackageManager.PERMISSION_GRANTED) {

  ActivityCompat.requestPermissions(MainActivity.this,
    new String[] {
      Manifest.permission.CAMERA
    }, 1);
}




@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
  if (grantResults.length > 0) {
    if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
      if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.CAMERA)) {
        Toast.makeText(MainActivity.this, "We need this permission because this application will click picture for you. Request you to please close the application and allow the permission", Toast.LENGTH_LONG).show();

      }
    }
  }
  super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}





Output


Picture showing the output of the shouldShowRequestPermissionRationale method in android

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Sunday, December 15, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250