I used Arthur Hub's image clipping library but the function is not called. Ecco'onClickListener` for the app user to open the image selector / collector after checking the Android version:
profileImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getActivity(), "Permission denied", Toast.LENGTH_LONG).show();
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
} else {
ImagePicker();
}
}
else {
ImagePicker();
}
}
});
The function itself:
private void ImagePicker() {
CropImage.activity(mainImageUri)
.setGuidelines(CropImageView.Guidelines.ON)
.setAspectRatio(1, 1)
.start(getContext(),this);
}
And here is the onActivityResult
:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == Activity.RESULT_OK) {
mainImageUri = result.getUri();
profileImage.setImageURI(mainImageUri);
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
Exception error = result.getError();
}
}
}
I received an error before activating onclicklistener, but other than that there is nothing:
09-15 12:39:43.861 16086-16086/com.quicklauncher.buildup.blog2 E/ViewRootImpl: sendUserActionEvent() mView == null
So I'm completely lost on what could cause this problem. It worked well when I had it in the activity but in a fragment, it does not work. Please help! Thank you.