nativescript-camera icon indicating copy to clipboard operation
nativescript-camera copied to clipboard

After taking a picture, I get an error 'cancelled'

Open butaminas opened this issue 6 years ago • 11 comments

Which platform(s) does your issue occur on?

  • Android
  • 10.0
  • emulator. Pixel 3a

I'm developing an app on nativescript-vue and using this particular package on a onShowFileChooser event by extending the WebChromeClient.

The idea is to make the camera to show when clicking a <input type='file' /> button on a webview.

First of all, I request user permissions on load like this:

mounted() {
            requestPermissions()
},

Then on the onShowFileChooser I do something like this:

onShowFileChooser: function (WebView, ValueCallback, FileChooserParams) {
                        camera.takePicture()
                            .then(function (imageAsset) {
                                console.log("Result is an image asset instance");
                                var image = new Image();
                                image.src = imageAsset;                               
                            }).catch(function (err) {
                            console.log("Error -> " + err.message);
                        });

Whenever I click the file input field in a webview the camera app appears and I can take a picture. After taking the picture and clicking the check mark to confirm, I get back to my app but in the console, I see:

'Error -> cancelled'

I've tried solution, mentioned here but this wasn't the case.

Why do I get this error? Besides that, anyone has any idea how to actually return the image to the input field?

Thanks!

butaminas avatar Oct 03 '19 19:10 butaminas

Have the same issue:

  • NS 6.1.1
  • Android
  • 10.0 (API 29)
  • emulator: Pixel 3

Also, when tried to select some image from gallery, get another error: [ERROR] Asset '/storage/emulated/0/Download/image.jpg' cannot be found.

AtoianAvetik avatar Oct 29 '19 11:10 AtoianAvetik

Have the same issue:

  • NS 6.1.1
  • Android
  • 10.0 (API 29)
  • emulator: Pixel 3

Still don't know the reason for this to happen but the only thing that worked for me was to downgrade to Android 8.0 (API 26) Pixel 2 and I've also selected CPU/ABI to be x86_64 instead of x86 (don't know if this had to do anything with it though).

butaminas avatar Oct 29 '19 11:10 butaminas

in camera.android.js
addline: nativeFile.getParentFile().mkdir();

image

dengyy-cq avatar Nov 01 '19 04:11 dengyy-cq

@dengyy-cq Thanks for reply, but your solution didn't help.

AtoianAvetik avatar Nov 01 '19 11:11 AtoianAvetik

Hi @butaminas ,

Can you please share a sample project with the mentioned setup where we can reproduce and eventually investigate and solve the issue you are observing.

DimitarTodorov avatar Nov 01 '19 13:11 DimitarTodorov

Same issue

uzarsalan avatar Nov 06 '19 06:11 uzarsalan

Hey! I had the same problem, solve it with this solution : Adding in the AndroidManifest.xml <application ... android:requestLegacyExternalStorage="true" ...

Found here

Luonnotar avatar Dec 03 '19 10:12 Luonnotar

Same issue here. Tried your solution @Luonnotar , but it does not build.

BUILD FAILED in 15s Unable to apply changes on device: emulator-5554. Error is: Command ./gradlew failed with exit code 1.

raphaelnm avatar Dec 16 '19 23:12 raphaelnm

pull request for fix: https://github.com/NativeScript/nativescript-camera/pull/237

AdamAtri avatar Jan 21 '20 19:01 AdamAtri

This issue makes camera plugin unable to work under Android 10 (API 29+) because API 29 uses scoped storage. For making your application compatible with current version of plugin, you can do 2 things to fix this:

a) put targetSdkVersion 28 into App_Resources/Android/app.gradle :

android {
  defaultConfig {
    ...
    targetSdkVersion 28
    ...

or:

b) Add android:requestLegacyExternalStorage="true" to application element in App_Resources/Android/src/main/AndroidManifest.xml

see https://developer.android.com/training/data-storage/compatibility

jakubgondar avatar Apr 17 '20 10:04 jakubgondar

@Gondy Thank you, that fixed the issue for me.

For anyone lurking here, my emulator was functioning fine, but my physical device would give this error right after confirming the photo was OK:

Error: java.io.FileNotFoundException: /storage/emulated/0/DCIM/Camera/NSIMG_20200419_174631.jpg: open failed: ENOENT (No such file or directory)

adding the targetSdkVersion 28 to my app.gradle resolved this for my physical device.

creative-gestalt avatar Apr 19 '20 23:04 creative-gestalt