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

No Image Data on Android 12

Open s5nicolay-dev opened this issue 1 year ago • 8 comments

Running fine on Android 10 (API level 29) with cordova Android 13.0.0 on Bluebird EF550.

Fails on Android 12 (API level 32) with cordova Android 13.0.0 on Bluebird EF551 with error message "No Image Data".

The project is a clean cordova HelloWorld project. cordova create test cordova platform add android cordova plugin add cordova-plugin-camera cordova build android

In console: var srcType = Camera.PictureSourceType.CAMERA; var options = setOptions(srcType);

function setOptions(srcType) { var options = { quality: 50, destinationType: Camera.DestinationType.FILE_URI, sourceType: srcType, encodingType: Camera.EncodingType.JPEG, mediaType: Camera.MediaType.PICTURE, allowEdit: false, correctOrientation: true } return options; }

navigator.camera.getPicture(function cameraSuccess(imageUri) { console.log("haha yes"); }, function cameraError(error) { console.debug(error); }, options);

Any suggestions?

s5nicolay-dev avatar Oct 22 '24 14:10 s5nicolay-dev

"No Image Data"

this usually indicates that the intent was cancelled and the user didn't select any image or didn't capture any image.

However on factory fresh devices when the user opens up the camera on the very first time I noticed that the camera app responds this way when it requests permission to use geolocation. Perhaps this is also what you're experiencing?

breautek avatar Oct 25 '24 23:10 breautek

Thank you for the suggestion. It sounds plausible that there is no image captured.

For the record it works to select PHOTOLIBRARY source and upload an image, however not capture.

We have tried factory reset on the device without luck. The app requests permission and launches the camera, however no data returns and the error function is called. I have tried to enable and disable the Geolocation for the camera app.

s5nicolay-dev avatar Oct 29 '24 08:10 s5nicolay-dev

Can you try testing the dev build?

cordova plugin remove cordova-plugin-camera
cordova plugin add https://github.com/apache/cordova-plugin-camera.git

It is a new major so it includes several breaking changes which is currently noted in the docs PR that will be used for the announcement when it's formally released: https://github.com/apache/cordova-docs/pull/1374

But it contains significant improvements for Android kinda across the board.

Otherwise I'd suggest opening the project in Android Studio or use logcat to get the native logs to see if there is anything there that indicates why it's returning "No Image"

breautek avatar Oct 30 '24 01:10 breautek

Thanks for the advice!

I have just tested and still have the same issue. I will try to see if I can find anything in logcat, but not quite sure what to look for.

What I am trying is a clean HelloWorld cordova app (cordova create test) with cordova-plugin-camera 8.0.1-dev and Android 13 platform. The device is a Bluebird EF551R that is factory reset. The capture still calls error function with the error message "No Image Selected".

s5nicolay-dev avatar Oct 30 '24 14:10 s5nicolay-dev

I have noticed that the app has not requested access to (listed with access to) Camera in the device settings.

s5nicolay-dev avatar Oct 30 '24 14:10 s5nicolay-dev

I have just tested and still have the same issue. I will try to see if I can find anything in logcat, but not quite sure what to look for.

I'd suggest filtering logcat by your application id. Android Studio will do this by default if you run the project via Android Studio. (Do not do any AGP/Android Gradle Plugin upgrades when you open the project in Android Studio). The Android Studio project can be found at /platforms/android

Then you can dump the logcat as a text file here and when I find a chance I can look over it.

I have noticed that the app has not requested access to (listed with access to) Camera in the device settings.

CAMERA permission is not normally required unless if you're using the camera APIs directly, which this plugin does not. It delegates to the camera application installed on the device.

Normally the camera application contains the CAMERA permission so that they can operate the camera and send the result back to the requesting app. However there have been reports of camera applications not handling this correctly, and will not work unless if the application itself has the CAMERA permission. Which I'm beginning to think your case is this.

A workaround might be to declare the CAMERA permission at the app level.

So you can try adding the following in your config.xml:

...
<platform name="android">
    <config-file target="AndroidManifest.xml" parent="/*" xmlns:android="http://schemas.android.com/apk/res/android">
        <uses-permission android:name="android.permission.CAMERA" />
    </config-file>
</platform>

The plugin does check if the CAMERA permission is declared and will request the permission if not granted. It's considered privacy sensitive so the CAMERA permission isn't declared automatically especially when it's normally not required. If this does solve your issue, it indicates a problem within the camera app itself.

breautek avatar Oct 30 '24 15:10 breautek

Thank you very much for your help. I have tried your suggestions. Unfortunately it does still not work, however maybe the logcat dump can provide some details? I noticed that after adding the config.xml change the app prompted for permission to record video.

Here is the logcat dump. Can you see any indication of what is going wrong? Bluebird-EF551-Android-12_2024-10-31_095522.txt

s5nicolay-dev avatar Oct 31 '24 09:10 s5nicolay-dev

Camera plugin v8 streamlines support for scoped storage which might have addressed this issue, or at the very least provide more meaningful error messages.

See https://cordova.apache.org/announcements/2024/11/02/camera-plugin-camera-8.0.0.html for more details

breautek avatar Mar 16 '25 00:03 breautek