cordova-plugin-camera
cordova-plugin-camera copied to clipboard
Crop not working on Android 10 and 11
Bug Report
Problem
With the latest versions crop functionality is not working on Android 10 and 11 (target SDK 29)
What is expected to happen?
Cropped image is delivered successfully
What does actually happen?
Crop throws an exception
Information
System.err: java.io.FileNotFoundException: /data/user/0/{app_name}/cache/1616872358512.jpg: open failed: ENOENT (No such file or directory) : Failed to UpdateQosForCgroupInner, tid=0, policy=10
DecorView: showOrHideHighlightView: hasFocus=false; winMode=1; isMrgNull=true
HwNetworkManagementService: code == CODE_SET_CHR_REPORT_APP_LIST
System.err: at libcore.io.IoBridge.open(IoBridge.java:496)
System.err: at java.io.FileInputStream.
Environment, Platform, Device
Android 10 and 11 Cordova Android 9 cordova-plugin-camera 5.0.1 android:requestLegacyExternalStorage="true" is added to AndroidManifest.xml
Also have the same issue, but currently only on Android 11. Got it working on Android 10.
Environment Cordova Android 9.0.0 cordova-plugin-camera 4.1.0 android:requestLegacyExternalStorage="true" is added to AndroidManifest.xml
$scope.takePicture = function () { var options = { quality: 85, destinationType: Camera.DestinationType.DATA_URL, sourceType: Camera.PictureSourceType.CAMERA, allowEdit: true, encodingType: Camera.EncodingType.JPEG, targetWidth: 800, targetHeight: 600, popoverOptions: CameraPopoverOptions, saveToPhotoAlbum: true };
I am also facing same problem in android 11. any solution....?
Same here. We had to disable crop (allowEdit: false) on Android as a workaround.
@p-caetano, I need crop function also.
(allowEdit: false) also not working.
Anyone got a solution please update it, I too facing the same issue in the android 11 crash !!!...
Hi,
This issue has become a bit of a headache.
Does anyone maybe know if this issue will be fixed in the next release?
I resolved the issue by changing the source code in CameraLauncher.java file, the issue is that android 11 does not allow access to URIs created from URI.fromFile from one application to another. For example, in the performcrop method we are generating a
croppedUri = Uri.fromFile(createCaptureFile(this.encodingType, System.currentTimeMillis() + ""));
and passing it to other activity therefore the receiving application will not have access to the croppedUri and throws an error like Access Denied or Editing is not allowed for this image.
So in order to resolve that we need to create a URI from FileProvider.getUriForFile().
I know it may sound silly. but replace with the following in performCrop method solved it for me.
croppedUri = picUri;
It worked for me on Android 10 and 11.
Please let me know your thoughts.
Thanks.
hi @bilalsaeed can you elaborate on that ? where did you made the change ? on CameraLauncher.java file ? in what line ? i can see there many croppedUri commands...
Hi @brunoalex.
I made that change in CameraLauncher.java file on line 441. I am attaching the file in this comment. Please also note that I am using 4.1.0 plugin. You also need to change path of camera plugin in config.xml and package.json files like the following
Package.json:
"cordova-plugin-camera": "./custom-plugins/cordova-plugin-camera-4.1.0",
config.xml:
<plugin name="cordova-plugin-camera" spec="./custom-plugins/cordova-plugin-camera-4.1.0">
<variable name="ANDROID_SUPPORT_V4_VERSION" value="27.+" />
</plugin>
The crop is working in my fork here https://github.com/alemit/cordova-plugin-camera by using the bilalsaeed initial hint + some more changes. It is compatible with android 30 target version. The config.xml is kind of deprecated already so in order to use it you would only need to add the cordova plugin out from the repository(e.g condova plugin add cordova-plugin-camera@git+https://github.com/alemit/cordova-plugin-camera.git)
Hi @bilalsaeed
I am using allowEdit:"true" for cropping square and rectangle . As per requirement i need to crop text so facing issue cropping text like address in android 11. After cropping nothing is happing following your steps still facing same issue.
I also used cordova-plugin-crop plugin but its allowing square cropping not rectangular.
Please help me ......Thanks
Hi @Jeetuy
Please remove cordova camera plugin and add the one @alemit created. This may temporarily resolve your issue.
Best,
allowEdit is unpredictable on Android and it should not be used! The Android implementation of this plugin tries to find and use an application on the user's device to do image cropping. The plugin has no control over what application the user selects to perform the image cropping and it is very possible that the user could choose an incompatible option and cause the plugin to fail. This sometimes works because most devices come with an application that handles cropping in a way that is compatible with this plugin (Google Photos), but it is unwise to rely on that being the case. If image editing is essential to your application, consider seeking a third party library or plugin that provides its own image editing utility for a more robust solution.
https://github.com/apache/cordova-plugin-camera#android-quirks-1