Android-Image-Cropper
Android-Image-Cropper copied to clipboard
not Work in ANDROID 11
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
π¨π¨π¨π¨π¨ 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
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"
@ankiitdev open an issue in the library repository or you can even open a PR with the fix
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>
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
);
}
}
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
Has anyone forked this and created a working version for SDK 30?
@donhill
please readΒ #858
All my messages in this thread point to a forked solution and update library
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: @.***>
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/