apache / cordova-plugin-camera

Apache Cordova Plugin camera
https://cordova.apache.org/
Apache License 2.0
960 stars 1.52k forks source link

cordova-plugin-camerea is Incompatible with android 10 #520

Closed Super-Jiang closed 4 years ago

Super-Jiang commented 4 years ago

Bug Report

cordova-plugin-camerea is Incompatible android 10

Problem

I test the HUAWEI HONOR 20 Pro Android 10 version of the machine. When using the plug-in to take photos, there is no response after clicking the capture button (a flash will appear, and the shooting will not succeed), no matter the front and rear cameras.

What is expected to happen?

I test the HUAWEI HONOR 20 Pro Android 10 version of the machine. When using the plug-in to take photos, there is no response after clicking the capture button (a flash will appear, and the shooting will not succeed), no matter the front and rear cameras.

What does actually happen?

I test the HUAWEI HONOR 20 Pro Android 10 version of the machine. When using the plug-in to take photos, there is no response after clicking the capture button (a flash will appear, and the shooting will not succeed), no matter the front and rear cameras.

Information

Command or Code

$cordovaCamera.getPicture(options).then(function(imageData) {·······

Environment, Platform, Device

android 10 honor 20 pro phone

Version information

Checklist

breautek commented 4 years ago

Are you using FILE_URI or DATA_URL DestinationType?

Super-Jiang commented 4 years ago

您正在使用FILE_URI还是DATA_URL DestinationType? const options = { quality: 100, destinationType: Camera.DestinationType.DATA_URL, sourceType: Camera.PictureSourceType.CAMERA, encodingType: Camera.EncodingType.JPEG, targetWidth: 1000, targetHeight: 500 };

breautek commented 4 years ago

You may need to refactor your code to use FILE_URI instead. See why below...

NOTE: Photo resolution on newer devices is quite good. Photos selected from the device's gallery are not downscaled to a lower quality, even if a quality parameter is specified. To avoid common memory problems, set Camera.destinationType to FILE_URI rather than DATA_URL.

https://github.com/apache/cordova-plugin-camera#cameragetpicturesuccesscallback-errorcallback-options

I also go into a bit more detail in this comment

Super-Jiang commented 4 years ago

可能您需要重构代码以FILE_URI代替使用。请在下面查看原因...

注意:在较新的设备上的照片分辨率非常好。再次指定了质量参数,从设备库中选择的照片也不会缩小到替换质量。为避免常见的内存问题,替换Camera.destinationType设置为FILE_URI而不是DATA_URL。

https://github.com/apache/cordova-plugin-camera#cameragetpicturessuccesscallback-errorcallback-options

我也在此评论中更详细地介绍了

You may need to refactor your code to use FILE_URI instead. See why below...

NOTE: Photo resolution on newer devices is quite good. Photos selected from the device's gallery are not downscaled to a lower quality, even if a quality parameter is specified. To avoid common memory problems, set Camera.destinationType to FILE_URI rather than DATA_URL.

https://github.com/apache/cordova-plugin-camera#cameragetpicturesuccesscallback-errorcallback-options

I also go into a bit more detail in this comment

I did it the way you said to change the destinationType to Camera.DestinationType.FILE_URI, but it's still the same. The photos can't be taken successfully. By the way, when I use the data_url, the first photo can be successful. As long as I don't exit the photo page, I can take multiple successful photos, but when I exit the photo page and enter again, I can't be successful. When I shut down and restart my mobile phone, I can succeed for the first time, and then I can't. the two methods are the same. Is a process not released or occupied? Here is my code. I changed quality and removed targetwidth and targetheight:

Const options ={

Quality: 50,

Destinationtype: camera.destinationtype.file_uri,

Sourcetype: camera.picturesourcetype.camera,

Encodingtype: camera.encodingtype.jpeg,

}

$cordovacamera. Getpicture (options). Then (function (imagedata){}

breautek commented 4 years ago

If this can be reproduced in a plain cordova app with minimum features required to reproduce this (without ionic, etc), then the next step is to create a sample reproduction app.

https://github.com/apache/cordova-contribute/blob/master/create-reproduction.md

I don't personally own an android 10 device, but I can use an android 10 simulator, and I have an android 9 physical device that I can use to test as well.

Super-Jiang commented 4 years ago

如果可以使用普通的cordova应用程序复制此文件,并且具有复制此文件所需的最少功能(无离子等),那么下一步就是创建一个示例复制应用程序。

https://github.com/apache/cordova-contribute/blob/master/create-reproduction.md

我个人不拥有android 10设备,但是我可以使用android 10模拟器,并且我也可以使用android 9物理设备进行测试。

If this can be reproduced in a plain cordova app with minimum features required to reproduce this (without ionic, etc), then the next step is to create a sample reproduction app.

https://github.com/apache/cordova-contribute/blob/master/create-reproduction.md

I don't personally own an android 10 device, but I can use an android 10 simulator, and I have an android 9 physical device that I can use to test as well.

OK, sir, I created a new application according to what you said. Because the initial camera application of ionic, I created a project -- [my first app| an example application that builds a camera with gallery], and then I compiled and packaged the application, but unfortunately, after the test, there will be previous problems. Below is the mobile video recording : https://github.com/super-jiang/testcordovacamera/blob/master/18def8599d0b1de7027faca6b4544152.mp4 APK file: https://github.com/super-jiang/testcordovacamera/blob/master/app-debug.apk. Because it's all initial code, no changes have been made, so I didn't commit the code. If so, I will submit it. Do you need any other information?

Super-Jiang commented 4 years ago

I didn't find this problem in Android 9, but when I upgraded my phone to version 10, the problem occurred.

breautek commented 4 years ago

An APK code won't help any maintainers debug the problem. We need a project with the source code that reproduces this issue. To be clear, I'm not asking you to share your app code that you're developing, just a new simple cordova app that has the bare minimum required to reproduce your issue.

This way, maintainers can build the APK using the provided source code and (hopefully) reproduce the issue on their end. Once the issue is reproduced, the repository can be used as a test and confirm that the issue is resolved when they apply patches.

Super-Jiang commented 4 years ago

An APK code won't help any maintainers debug the problem. We need a project with the source code that reproduces this issue. To be clear, I'm not asking you to share your app code that you're developing, just a new simple cordova app that has the bare minimum required to reproduce your issue.

This way, maintainers can build the APK using the provided source code and (hopefully) reproduce the issue on their end. Once the issue is reproduced, the repository can be used as a test and confirm that the issue is resolved when they apply patches. Thank you very much for your answer, when I created a Cordova demo instead of an ionic-Cordova-demo. I found that Cordova demo is no problem, so I rechecked some of my code and found that I did not add 【document.addeventlistener ("deviceready", ondevicereready, false); function onDeviceReady() { destinationType=navigator.camera.DestinationType; }】 When I added this, I found that the problem no longer appeared. Thank you again.

AmrAbdalrahman commented 4 years ago

@Super-Jiang I tried to add

document.addEventListener("deviceready", onDeviceReady, false);
        function onDeviceReady() {
            navigator.camera.DestinationType;
        }

in constructor get

Property 'camera' does not exist on type 'Navigator'

krushndayshmookh commented 3 years ago

If this can be reproduced in a plain cordova app with minimum features required to reproduce this (without ionic, etc), then the next step is to create a sample reproduction app.

https://github.com/apache/cordova-contribute/blob/master/create-reproduction.md

I don't personally own an android 10 device, but I can use an android 10 simulator, and I have an android 9 physical device that I can use to test as well.

yes. i've tried on android 10 on device and issue persists.

krushndayshmookh commented 3 years ago

in fact, even capacitor crashes with basic simple camera app on android 10

guillermohaad commented 3 years ago

hi @breautek am working on Cordova 9 platform . and use cordova -plugin-camera@5.0.0 Everything work fine , But the problem occur when am enable the saveToPhotoAlbum option , On Android 10 its not work , throw Camera error . & also some cellphone after capture photo the app automatically shutdown

Thank you

AleffBruno commented 2 years ago

Clear / delete previous camera-plugin version and install this version: "5.0.2"

Put this in your package.json ( if there is some package.json ) : "cordova-plugin-camera": "5.0.2".

Attention to .lock files, normally that file saves another version and could cause some troubles

👍