not Work in ANDROID 11
IMWaqasFarooq opened this issue ยท 10 comments
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.
<!-- resource file to create -->
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
The issue happens here:
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
);
}
}
Has anyone forked this and created a working version for SDK 30?
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
libraryOn Mon, Jan 10, 2022 at 8:34 PM Canato @.***> wrote:
@donhill https://github.com/donhill
โ
Reply to this email directly, view it on GitHub
#850 (comment),
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/