I am getting image cropping like this:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
//do some activity based on permission granted or declined.
} else {
CropImage.activity(mainImageURI)
.setGuidelines(CropImageView.Guidelines.ON)
.setAspectRatio(1,1)
.setAutoZoomEnabled(false)
.start(this);
;
}
}
My question is I want to do some activity right after the permission is granted or declined. In current scenario, I can first grant the permission and then again click again the imageview I am using, and then the cropping. But I want to have one activity right after the permission is granted and one if permission is denied.
You should override onRequestPermissionsResult
in your activity in order to get notified whenever permission is granted or not:
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PERMISSIONS_CODE) {
for (int i = 0; i < permissions.length; i++) {
String permission = permissions[i];
int grantResult = grantResults[i];
if (permission.equals(Manifest.permission.READ_EXTERNAL_STORAGE)) {
if (grantResult == PackageManager.PERMISSION_GRANTED) {
// TODO Open The Crop Activity
} else {
// TODO Tell the user your app can't function properly
}
}
}
}
}