ArthurHub / Android-Image-Cropper

Image Cropping Library for Android, optimized for Camera / Gallery.
Apache License 2.0
6.4k stars 1.38k forks source link

not Work in ANDROID 11 #850

Open IMWaqasFarooq opened 3 years ago

IMWaqasFarooq commented 3 years ago

Its not working in android 11, the picture is not coming after capturing, same issue was raised here by others but they got a suggestion to change some code in CropActivity, but when i try to change the code , i unable to change it because that all files are read-only files not editable

Canato commented 3 years ago

🚨🚨🚨🚨🚨 THIS LIBRARY IS NOT MAINTAINED, PLEASE READ THIS 🚨🚨🚨🚨🚨 #838

To avoid your issues, please use the latest updated library: https://github.com/CanHub/Android-Image-Cropper

ankiitdev commented 3 years ago

This CanHub library too is not working on my device. I'm using Poco M2 Pro (Android 11, MIUI 12). I tried with their sample code as well. Even that is not working. As soon as I choose any image from gallery or camera, it shows an error "image cropping image was cancelled by the user"

Canato commented 3 years ago

@ankiitdev open an issue in the library repository or you can even open a PR with the fix

Prasad8237 commented 3 years ago

You can try with following one . It may help you (Only for taking picture from camera in android 29 and above)

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getApplicationContext().getPackageManager()) != null) {
        // Create the File where the photo should go
        try {
            photoFile = getFilename(getApplicationContext());
        } catch (IOException ex) {
            ex.printStackTrace();
            // Error occurred while creating the File
        }
        if (photoFile != null) {
            picUri = FileProvider.getUriForFile(getApplicationContext(),
                    BuildConfig.APPLICATION_ID + ".provider",
                    photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, picUri);
            startActivityForResult(takePictureIntent, CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE);
        }
    }

public File getFilename(Context context) throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); String mFileName = "JPEG" + timeStamp + ""; File storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES); File mFile = File.createTempFile(mFileName, ".jpg", storageDir); return mFile;

}

if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) { CropImage.ActivityResult result = CropImage.getActivityResult(data); if (resultCode == RESULT_OK && result!=null) { Uri resultUri = result.getUri(); picUri=resultUri; mCurrentPhotoPath = resultUri.getPath(); croppedImage.setImageURI(resultUri);

            Log.e("uploadImage", "=" + mCurrentPhotoPath);

        }
        if(resultCode==-1 && data==null)
        {

            CropImage.activity(picUri)
                    .setGuidelines(CropImageView.Guidelines.ON)
                    .setAspectRatio(1, 1) //You can skip this for free form aspect ratio)
                    .start(this);

        }
    }

Simply use above code to get image from camera and for gallery you can use regular code. Also you need to add in manifest below code. <provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true">

        <!-- resource file to create -->
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths" />
    </provider>
zxyufan commented 3 years ago

The issue happens here: https://github.com/ArthurHub/Android-Image-Cropper/blob/2a4a425668bfff1329dd5bfb1b80b0829bb4cc67/cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImage.java#L342

It is no longer appropriate to use Uri.fromFile(file) in Android 11, we need to use FileProvider instead. Patch sample may look like this:

if (getImage != null) {
    File outputFile = new File(getImage.getPath(), "pickImageResult.jpeg");
    if (Build.VERSION.SDK_INT < 24) {
        outputFileUri = Uri.fromFile(outputFile);
    } else {
        outputFileUri = FileProvider.getUriForFile(
            context, "YOUR.APP.PACKAGE.provider", outputFile
        );
    }
}
Canato commented 3 years ago

If you want a solution : https://github.com/CanHub/Android-Image-Cropper/wiki/%F0%9F%9A%A8-How-to-migrate-Android-Image-Cropper--%F0%9F%9A%A8

donhill commented 2 years ago

Has anyone forked this and created a working version for SDK 30?

Canato commented 2 years ago

@donhill

please readΒ #858

All my messages in this thread point to a forked solution and update library

donhill commented 2 years ago

Thanks. I was expecting a wrapper API that would work with existing code. It seems that the API for this project went in a diff direction. Maybe an adapter extension function would help folks with migration from the old library

On Mon, Jan 10, 2022 at 8:34 PM Canato @.***> wrote:

@donhill https://github.com/donhill

please read #858 https://github.com/ArthurHub/Android-Image-Cropper/issues/858

β€” Reply to this email directly, view it on GitHub https://github.com/ArthurHub/Android-Image-Cropper/issues/850#issuecomment-1009545207, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABRJI5PALG4RWVS3TDVMTTUVOJK3ANCNFSM5C2YF7ZQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

Canato commented 2 years ago

Thanks. I was expecting a wrapper API that would work with existing code. It seems that the API for this project went in a diff direction. Maybe an adapter extension function would help folks with migration from the old library

On Mon, Jan 10, 2022 at 8:34 PM Canato @.***> wrote:

@donhill https://github.com/donhill

please read #858 https://github.com/ArthurHub/Android-Image-Cropper/issues/858

β€” Reply to this email directly, view it on GitHub https://github.com/ArthurHub/Android-Image-Cropper/issues/850#issuecomment-1009545207, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABRJI5PALG4RWVS3TDVMTTUVOJK3ANCNFSM5C2YF7ZQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

On the new project README there is a guide for migrating from one Library to the other, let me know if it is not enough and we can work into something :D.

There were some changes in need to bring this amazing lib up to date, but always open to keep improving \o/