Android-Image-Cropper icon indicating copy to clipboard operation
Android-Image-Cropper copied to clipboard

CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE is not working in fragment

Open emondd4 opened this issue 4 years ago • 11 comments

emondd4 avatar Jun 02 '20 17:06 emondd4

yeah, for me too!:( Did you find any solution, mate?

aminPial avatar Jun 06 '20 17:06 aminPial

Yes also not working for me

anupdey99 avatar Jun 11 '20 13:06 anupdey99

I have tried couple of times then stop trying using it inside fragment. In Activity it just works like charm, no issues. But in Samsung Galaxy J7 I found an issue of crashing camera app every time.

aminPial avatar Jun 11 '20 17:06 aminPial

Solved it

public void selectImage(){
Intent intent = CropImage.activity()
                        .setGuidelines(CropImageView.Guidelines.ON)
                        .setAspectRatio(35,50)
                        .getIntent(getContext());
                startActivityForResult(intent, CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE);
}

 @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 == RESULT_OK) {
                    Uri imageUri = result.getUri();
                    InputStream inputStream;
                    try {
                        inputStream = getActivity().getContentResolver().openInputStream(imageUri);
                        Bitmap photo = BitmapFactory.decodeStream(inputStream);
                        image1.setImageBitmap(photo);

                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }

                } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
                    Toast.makeText(getActivity(), "Cropping failed: " + result.getError(), Toast.LENGTH_LONG).show();
                }
            }else {
                Toast.makeText(getActivity(), ""+requestCode, Toast.LENGTH_SHORT).show();
            }
    }

CallieMuch avatar Jun 24 '20 14:06 CallieMuch

@CallieMuch Thanks a lot man. I tested your code and it works. @emondd4 please close the issue if this solutions worked for you. Cheers guys!:)

aminPial avatar Jul 08 '20 14:07 aminPial

Is this working for everyone with Android R?

joseph-acc avatar Jul 09 '20 20:07 joseph-acc

@CallieMuch thanks man your code is working but when you select camera it's not working

MuhammadArslan786 avatar Jul 18 '20 21:07 MuhammadArslan786

@CallieMuch thanks man your code is working but when you select camera it's not working

Are you using a Samsung Device? Mine is not working on Samsung Galaxy Model. Camera kept crashing:(

aminPial avatar Jul 21 '20 07:07 aminPial

Hey!

I start a new project to handover this library https://github.com/CanHub/Android-Image-Cropper

The ideia is that we keep improving because this project don’t have updates since 2018 Hope I can count with your help.

Open to contribute, next pieces of work will be Android 11 permissions, refactor into Kotlin and ActivityContract

Canato avatar Nov 27 '20 16:11 Canato

Hey!

I start a new project to handover this library https://github.com/CanHub/Android-Image-Cropper

The ideia is that we keep improving because this project don’t have updates since 2018 Hope I can count with your help.

Open to contribute, next pieces of work will be Android 11 permissions, refactor into Kotlin and ActivityContract

Thanks for the help. I will use this in my next project. HOPE so.

MuhammadArslan786 avatar Nov 27 '20 19:11 MuhammadArslan786

I add a wiki how to migrate if you want, really easy @MuhammadArslan786

Canato avatar Nov 27 '20 20:11 Canato