Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gallery option is not showing #20

Closed
Viral891 opened this issue Dec 21, 2020 · 19 comments · Fixed by #53 or #55
Closed

Gallery option is not showing #20

Viral891 opened this issue Dec 21, 2020 · 19 comments · Fixed by #53 or #55

Comments

@Viral891
Copy link

Viral891 commented Dec 21, 2020

Screenshot_2020-12-21-19-41-11-983_android

Android 10

Using Android Studio 3.6.3

I followed the steps as given but only camera and file options show up in the intent . The gallery option is not visible.I am also using the latest version of the library.

@Canato
Copy link
Member

Canato commented Dec 21, 2020

Which version of the library are you using @Viral891 ?

@Viral891
Copy link
Author

Which version of the library are you using @Viral891 ?

implementation 'com.canhub.cropper:android-image-cropper:1.1.0'

@Canato Canato added the bug label Dec 21, 2020
@Canato
Copy link
Member

Canato commented Dec 21, 2020

OK, look like a bug, will investigate later.

@Viral891 could you please add

  • The piece of code you call to show this
  • The device used

Thanks!

@Viral891
Copy link
Author

Viral891 commented Dec 22, 2020

Device Name: Mi Redmi Note 7 Pro
Android Version: Android 10
Please check on all Android 10 devices

<ImageView android:id="@+id/profileEditImg" android:src="@drawable/camera_icon" android:layout_width="30dp" android:layout_height="30dp" android:layout_alignParentRight="true" android:layout_alignParentBottom="true" android:elevation="5dp" />

`Permission Library:
implementation 'gun0912.ted:tedpermission:2.2.3'

Permission Code:
private void takePermissionNGetImg() {
PermissionListener permissionlistener = new PermissionListener() {
@OverRide
public void onPermissionGranted() {
onSelectImageClick();
}

        @Override
        public void onPermissionDenied(List<String> deniedPermissions) {
            AppHelper.showSnackBar(mainContainer, "Permission denied!", Snackbar.LENGTH_LONG);
        }
    };

    TedPermission.with(CustomerInformationFormActivity.this)
            .setPermissionListener(permissionlistener)
            .setDeniedTitle("Permission denied")
            .setDeniedMessage("If you reject this permission, you will be unable to use this service\n\nPlease turn on permissions in Settings")
            .setGotoSettingButtonText("Go To Settings")
            .setPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA)
            .check();
}

//Permission Granted
public void onSelectImageClick() {
CropImage.startPickImageActivity(this);
}

@Override
@SuppressLint("NewApi")
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    try {
        if (requestCode == CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
            Uri imageUri = CropImage.getPickImageResultUri(this, data);

            if (CropImage.isReadExternalStoragePermissionsRequired(this, imageUri)) {
                mCropImageUri = imageUri;
                requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 0);
            } else {
                startCropImageActivity(imageUri);
            }
        }

        if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
            final CropImage.ActivityResult result = CropImage.getActivityResult(data);
            if (resultCode == RESULT_OK) {
                final Uri uri = result.getUri();
                Bitmap bitmap = null;
                try {
                    bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
                    bitmap = Bitmap.createScaledBitmap(bitmap, 500, 500, true);

                    final Bitmap finalBitmap = bitmap;
                    Glide.with(CustomerInformationFormActivity.this).asBitmap().load(uri).into(new BitmapImageViewTarget(userImg) {
                        @Override
                        public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                            super.onResourceReady(resource, transition);

                            try {
                                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                finalBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
                                byte[] b = baos.toByteArray();
                                temp = Base64.encodeToString(b, Base64.DEFAULT);

                                RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(CustomerInformationFormActivity.this.getResources(), resource);
                                circularBitmapDrawable.setCircular(true);
                                userImg.setImageDrawable(circularBitmapDrawable);

                                String extension = ".jpg";
                            } catch (Exception e) {
                                Logger.error(e.getLocalizedMessage());
                            }
                        }
                    });
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
                Toast.makeText(this, "Somethiing went wrong...", Toast.LENGTH_LONG).show();
            }
        }
    } catch (Exception e) {
        Logger.log(e.getLocalizedMessage());
    }
}

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    if (mCropImageUri != null && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        startCropImageActivity(mCropImageUri);
    } else {
        Toast.makeText(this, "Cancelling, required permissions are not granted", Toast.LENGTH_LONG).show();
    }
}

/**
 * Start crop image activity for the given image.
 */
private void startCropImageActivity(Uri imageUri) {
    CropImage.activity(imageUri)
            .setCropMenuCropButtonTitle("Next")
            .setActivityTitle("Crop Image")
            .setGuidelines(CropImageView.Guidelines.OFF)
            .setMultiTouchEnabled(false)
            .setFixAspectRatio(true)
            .setAutoZoomEnabled(false)
            .start(this);
}

`

@Canato
Copy link
Member

Canato commented Dec 23, 2020

Please check on all Android 10 devices

sorry this is not possible.

About the Bug

@Viral891 could not reproduce, look like a permissions library issue.
If you look in their issues ParkSangGwon/TedPermission#108
They are having issues with Android 10/11 permissions

Google change a lot the storage permissions on Android 10 and enforce it for Android 11. We change the code to use Scope Storage and the permissions need to be update

Would suggest to use google Request Permissions, like this android/permissions-samples#8

Local Test

If you want to test the library code without interferences in your device, checkout the main branch and build the quick-start app in your test device and try to get the image from the gallery.

Let me know the output so we can keep digging if need

@rexyrex
Copy link

rexyrex commented Jan 4, 2021

I have the same issue.

Android 10.
Galaxy Note 10+
implementation 'com.canhub.cropper:android-image-cropper:1.1.1'

CropImage.activity() .setGuidelines(CropImageView.Guidelines.ON) .setAspectRatio(1,1) .start(activity);

@Canato
Copy link
Member

Canato commented Jan 4, 2021

@rexyrex Could you reproduce with one of the build provide in the project like I ask?

quick-start or sample or test

@rexyrex
Copy link

rexyrex commented Jan 6, 2021

@Canato I'm quite new to this. How would I go about testing the different builds that you mentioned above? I've only tried implementing the most recent version into my app

@Canato
Copy link
Member

Canato commented Jan 6, 2021

@Canato I'm quite new to this. How would I go about testing the different builds that you mentioned above? I've only tried implementing the most recent version into my app

Hey @rexyrex you will need to import this project in your machine and build the apps in your emulator/device for test

@rexyrex
Copy link

rexyrex commented Jan 14, 2021

@Canato I finally found the time to get around to this.

I've tested all 3 projects and only "Camera" and "Files" is listed

@Canato Canato added the pinned label Jan 25, 2021
@Canato
Copy link
Member

Canato commented Feb 7, 2021

This will be done with a code refactor of startPickImageActivity method.
Need to fix and rethink the intent to open Camera, Gallery and storage

@datdescartes
Copy link
Contributor

We've encountered the same error.
I have just created a PR for this. Simply by copying the source code for gallery intents from legacy source code.
Please review.

@kaustubhkp
Copy link

@datdescartes what about camera option not showing for few phones?

@datdescartes
Copy link
Contributor

@kaustubhkp could you tell me which device and android version?

@datdescartes
Copy link
Contributor

@kaustubhkp I've just updated the PR that possibly fix the camera bug.

@kaustubhkp
Copy link

kaustubhkp commented Feb 10, 2021

@datdescartes here are details about issue I was mentioning #52

@datdescartes
Copy link
Contributor

@kaustubhkp I see. Thank you.
I think that my PR also fixes that bug

@kaustubhkp
Copy link

@Canato do you have any idea how long will this PR take to merge to library ?

@Canato
Copy link
Member

Canato commented Feb 10, 2021

@kaustubhkp will do some tests, if everything is fine we merge now and I open the release PR

datdescartes pushed a commit to datdescartes/Android-Image-Cropper that referenced this issue Feb 11, 2021
Canato pushed a commit that referenced this issue Feb 11, 2021
* fixed bug that Gallery picker option is not showing

* fixing android Q permission

* removed unused query permission

* added workaround for android Q that only shows up 2 items

* removing TODO, adding CHANGELOG for #20, #52 fixes

* bugfixed, handle picker result on fragment

Co-authored-by: dat <datvu@macbook>
@Canato Canato unpinned this issue Feb 11, 2021
@Canato Canato linked a pull request Feb 11, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants