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
Click to Enlarge