NativeScript / nativescript-camera

NativeScript plugin to empower using device camera.
Apache License 2.0
92 stars 47 forks source link

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

Open butaminas opened 4 years ago

butaminas commented 4 years ago

Which platform(s) does your issue occur on?

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!

AtoianAvetik commented 4 years ago

Have the same issue:

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

butaminas commented 4 years ago

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

dengyy-cq commented 4 years ago

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

image

AtoianAvetik commented 4 years ago

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

DimitarTodorov commented 4 years ago

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.

uzarsalan commented 4 years ago

Same issue

Luonnotar commented 4 years ago

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

Found here

raphaelnm commented 4 years ago

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.

AdamAtri commented 4 years ago

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

jakubgondar commented 4 years ago

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

creative-gestalt commented 4 years ago

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