cordova-plugin-camera icon indicating copy to clipboard operation
cordova-plugin-camera copied to clipboard

Crop not working on Android 10 and 11

Open cvettelina opened this issue 3 years ago • 13 comments

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.(FileInputStream.java:159) System.err: at java.io.FileInputStream.(FileInputStream.java:115) System.err: at android.media.ExifInterface.initForFilename(ExifInterface.java:2363)

Environment, Platform, Device

Android 10 and 11 Cordova Android 9 cordova-plugin-camera 5.0.1 android:requestLegacyExternalStorage="true" is added to AndroidManifest.xml

cvettelina avatar Mar 29 '21 19:03 cvettelina

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 };

fcsteenkamp avatar Apr 01 '21 07:04 fcsteenkamp

I am also facing same problem in android 11. any solution....?

rawcoolpad avatar Apr 05 '21 11:04 rawcoolpad

Same here. We had to disable crop (allowEdit: false) on Android as a workaround.

p-caetano avatar Apr 05 '21 11:04 p-caetano

@p-caetano, I need crop function also.

rawcoolpad avatar Apr 05 '21 11:04 rawcoolpad

(allowEdit: false) also not working.

ishtiaqshariffTopdevz avatar Apr 07 '21 15:04 ishtiaqshariffTopdevz

Anyone got a solution please update it, I too facing the same issue in the android 11 crash !!!...

satheeshkumartitan avatar Apr 21 '21 08:04 satheeshkumartitan

Hi,

This issue has become a bit of a headache.

Does anyone maybe know if this issue will be fixed in the next release?

fcsteenkamp avatar Jun 07 '21 06:06 fcsteenkamp

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.

bilalsaeed avatar Jun 20 '21 08:06 bilalsaeed

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...

brunoalex avatar Nov 18 '21 17:11 brunoalex

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>

CameraLauncher.txt

bilalsaeed avatar Nov 19 '21 10:11 bilalsaeed

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)

alemit avatar Jan 09 '22 08:01 alemit

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

Jeetuy avatar Feb 04 '22 17:02 Jeetuy

Hi @Jeetuy

Please remove cordova camera plugin and add the one @alemit created. This may temporarily resolve your issue.

Best,

bilalsaeed avatar Feb 07 '22 13:02 bilalsaeed

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

breautek avatar Sep 06 '23 11:09 breautek