Android-Image-Cropper
Android-Image-Cropper copied to clipboard
Workaround solution for Android 30
Starting with Android 30 external apps no longer can access directly files, so the solution would be to use a custom file provider.
You will have to do those changes:
In CropImage class, add a string customFileProvider :
public static String customFileProvider= "com.theartofdev.edmodo.cropper.genericFileProvider"; // the value is meaningless here, because you will need to override this anyway
Next change getCaptureImageOutputUri function as:
public static Uri getCaptureImageOutputUri(@NonNull Context context) {
Uri outputFileUri = null;
File folder = context.getExternalCacheDir();
File getImage = new File(folder.getPath(), "pickImageResult.jpeg");
if (getImage != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
outputFileUri = FileProvider.getUriForFile(context, customFileProvider,getImage);
} else{
outputFileUri = Uri.fromFile(getImage);
}
}
return outputFileUri;
}
And in getCameraIntent and getCameraIntents you will need to add the permissions as:
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
In your app, add the true value for:
CropImage.customFileProvider = "your.custom.app.package.name"+".genericfileprovider";
Just before making your call to the CropImage library:
CropImage.activity().setOutputUri(outputUri).setCropShape(CropShape.OVAL).setFixAspectRatio(true).start(MyCustomCallingActivity.this);
And at last you need to define the file provider in your AndroidManifest.xml (not going to explain this as is a bit out of the scope).
THIS LIBRARY IS NOT MAINTAINED, PLEASE READ THIS #818
I start a new project to handover this library https://github.com/CanHub/Android-Image-Cropper
The ideia is that we keep improving because this project don’t have updates since 2018 Hope I can count with your help.
Open to contribute, next pieces of work will be Android 11 permissions, refactor into Kotlin and ActivityContract
OBS: This issue was solved on the new library =)
@Arise Nice man.. It actually worked.. I was wondering what setOutputUri() is.. Then figured out Uri outputUri = Uri.fromFile(new File(requireActivity().getExternalCacheDir(),"image.jpg"));, if anyone required.. Thanks folk..
@Abhishek95872 how you edited the library ?
@Abhishek95872 how you edited the library ?
@ashcode1997 We have a new project handover from this one, where we are fixing it all.
https://github.com/CanHub/Android-Image-Cropper