0

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.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
BVB09
  • 805
  • 9
  • 19
  • Have a look at [this](https://github.com/ArthurHub/Android-Image-Cropper/tree/master/sample) sample project. – grrigore Sep 15 '18 at 10:50
  • I did come cross this project. I have been working on this problem for over 2 days now. Did not find the answer there. – BVB09 Sep 15 '18 at 10:55
  • Are you using an emulator? Or a physical device? According to [this](https://stackoverflow.com/questions/18028666/senduseractionevent-is-null) question that error can be ignored. – grrigore Sep 15 '18 at 10:58
  • I am using a Galaxy S5. Emulator results in the same. – BVB09 Sep 15 '18 at 11:03
  • Yes, I am ignoring the error. I dont think it has anything to do with the problem here. – BVB09 Sep 15 '18 at 11:03
  • No unfortunately it is not because on the emulator (Oreo SDK) I get the same result. – BVB09 Sep 15 '18 at 11:10
  • Try using a Nexus or other non-Samsung device in the emulator. If it works on non-Samsung devices, then it is not your fault, it is Samsung's. – grrigore Sep 15 '18 at 11:13
  • I don't know if this has to do with the problem, but you can try to add `android:onClick="profileImageClick"` to your `imageProfile` in XML and implement the method, getting rid of that `setOnClickListener`. – grrigore Sep 15 '18 at 11:15
  • I used Pixel 2 XL with the same result. I tried to using profileImageClick as well with the same result. I doubted that was the problem anyway. I even tried this solution and get a different set of errors: [https://stackoverflow.com/questions/38457826/image-crop-not-working-in-fragment] – BVB09 Sep 15 '18 at 11:25
  • In the solution you provided the OP is using `Log.e("resultUri ->", String.valueOf(resultUri));`. He's logging some data with the `error` tag. Are there any other errors? – grrigore Sep 15 '18 at 11:31
  • I added Logcat and go this error message since I am using Firebase: `09-15 13:41:41.531 22045-22045/com.quicklauncher.buildup.blog2 E/error ->: java.lang.RuntimeException: Failed to load sampled bitmap: https://firebasestorage.googleapis.com/v0/b/blog-4b318.appspot.com/o/profile_images%2FVTFp5Rd7D1TtTeAS9K3GLaSqQ1z2.jpg?alt=media&token=1080e278-5ad3-4d6c-affd-13a4c8de5144 No content provider: https://firebasestorage.googleapis.com/v0/b/blog-4b318.appspot.com/o/profile_images%2FVTFp5Rd7D1TtTeAS9K3GLaSqQ1z2.jpg?alt=media&token=1080e278-5ad3-4d6c-affd-13a4c8de5144` – BVB09 Sep 15 '18 at 11:44
  • But I dont see what this error has to do with the activity not being triggered. – BVB09 Sep 15 '18 at 11:44

0 Answers0