ArthurHub / ArthurHub/Android-Image-Cropper
Workaround solution for Android 30
- Dominant language
- Java
- Stars
- 6.4k
- Forks
- 1.4k
- PR merge metrics
- No merged PRs in 30d
Description
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).
Contributor guide
No contributing guide indexed for this repository
Research direction
Read the CropImage class and the getCaptureImageOutputUri, getCameraIntent, and getCameraIntents entry points first. Check the Android 30 URI and provider behavior alongside AndroidManifest.xml; done means callers can configure a custom provider and camera capture works with the required URI permissions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100