Giter Club home page Giter Club logo

Comments (19)

Viral891 avatar Viral891 commented on May 24, 2024 1

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);
}

`

from android-image-cropper.

datdescartes avatar datdescartes commented on May 24, 2024 1

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.

from android-image-cropper.

datdescartes avatar datdescartes commented on May 24, 2024 1

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

from android-image-cropper.

Canato avatar Canato commented on May 24, 2024 1

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

from android-image-cropper.

Canato avatar Canato commented on May 24, 2024

Which version of the library are you using @Viral891 ?

from android-image-cropper.

Viral891 avatar Viral891 commented on May 24, 2024

Which version of the library are you using @Viral891 ?

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

from android-image-cropper.

Canato avatar Canato commented on May 24, 2024

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!

from android-image-cropper.

Canato avatar Canato commented on May 24, 2024

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

from android-image-cropper.

rexyrex avatar rexyrex commented on May 24, 2024

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);

from android-image-cropper.

Canato avatar Canato commented on May 24, 2024

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

quick-start or sample or test

from android-image-cropper.

rexyrex avatar rexyrex commented on May 24, 2024

@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

from android-image-cropper.

Canato avatar Canato commented on May 24, 2024

@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

from android-image-cropper.

rexyrex avatar rexyrex commented on May 24, 2024

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

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

from android-image-cropper.

Canato avatar Canato commented on May 24, 2024

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

from android-image-cropper.

kaustubhkp avatar kaustubhkp commented on May 24, 2024

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

from android-image-cropper.

datdescartes avatar datdescartes commented on May 24, 2024

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

from android-image-cropper.

datdescartes avatar datdescartes commented on May 24, 2024

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

from android-image-cropper.

kaustubhkp avatar kaustubhkp commented on May 24, 2024

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

from android-image-cropper.

kaustubhkp avatar kaustubhkp commented on May 24, 2024

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

from android-image-cropper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.