本文介绍了在Phonegap应用程序上使用相机,只有HTML输入,没有Camera API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在没有Camera API的情况下通过HTML输入从手机相机应用中获取照片?

Is it possible to get a photo from camera in a phonegap app only with HTML input, without Camera API?

情景

我开发了一个应用程序并通过Phonegap封装它(构建)

I developed an app and encapsulated it through Phonegap (Build)

用户可以提交使用html文件输入的照片。但是没有选择从相机拍摄新照片,只有画廊和文件(以及任何其他存储应用程序,如驱动器或保管箱,如果是这种情况)。

Users can submit photos using html file input. But there is no option to take a new photo from camera, only gallery and files (and any other storage app like drive or dropbox, if it is the case).

我想启用相机选项,但没有PhoneGap的Camera API。

I would like to enable the camera option, but without the PhoneGap's Camera API.

解决方案

我尝试了以下解决方案但没有成功:

I've tried the following solutions without success:

1。 捕获属性(来自)

1. The "capture" attribute (from Raymond Camden post)

使用这种方法,您所要做的就是添加capture属性,如下所示:

With this method, all you have to do is to add the "capture" attribute like this:

<input type="file" capture="camera" accept="image/*" id="JustChooseAnID">

Raymond解释说,使用此方法,您不需要使用PhoneGap的Camera API,因为Google开发了此选项并在Google开发人员的中展示还有雷蒙德,它有效。

Raymond explains that with this method you don't need to use PhoneGap's Camera API since Google developed this option and showed it in a Google IO presentation and, according to Google devs and also Raymond, it works.

但是......不适合我。

But.. not for me.

2。配置Phonegap以询问相机的许可(来自)

2. Config Phonegap to ask camera's permission (from Jorge Lizaso's question)

也许相机选项没有显示,因为你的应用没有适当的权限

"Maybe the camera option is not showed up because your app doesn't have the proper permissions"

在上面的问题中,提到了4种间接询问并获得使用相机的适当权限的方法。

In the above question, 4 methods are mentioned to indirectly ask and receive the proper permissions to use the camera.

我已经尝试过方法2和4,虽然我的应用程序现在要求对于相机权限,我允许它正确,当我使用文件输入时,所有选项都显示(如图库和文件),但没有相机。

I have already tried methods 2 and 4 and, although my app now asks for camera permission and I allowed it properly, when I use the file input, all the options are presented (like gallery and files), but no camera.

3(和1)。使用最新版本的webkit与确保解决方案#1

3 (and 1). Use the latest version of webkit with Crosswalk to ensure solution #1

由于我的android webview可能过时(并且与解决方案#1不兼容),我决定在我的应用程序中包含可能的最佳webview:。

With the possibility of my android webview be outdated (and not compatible with solution #1), I decided to include in my app the best webview possible: the latest version of Google Chromium.

但是......再没有成功。

But.. no success again.

1,2和3合计

结果:没有...成功。

The result: no... success.

推荐答案

是的,有一个解决方案,无需Cordova / PhoneGap的Camera API 。

Yes, there is a solution, without the need for Cordova/PhoneGap's Camera API.

由于我所知的原因,(名为WebView +)比phonegap的Crossswalk更优化和调整为HTML5应用程序(请,我与Cocoon无关)。

For reasons that are beyond my knowledge, the webkit used in CocoonJS (named WebView+) is far more optimized and adjusted to HTML5 apps than phonegap's Crossswalk (please, I am not related to Cocoon).

我完全放弃了我的Phonegap config.xml设置并尝试了Cocoon builder。我使用了解决方案#1(文件输入中的捕获属性)并通过Cocoon添加了这些插件:

I discarded completely my Phonegap config.xml settings and tried Cocoon builder. I used the solution #1 (the capture attribute in file input) and added these plugins, via Cocoon:

<cocoon:plugin name="cordova-plugin-camera"/>
<cocoon:plugin name="cordova-plugin-media-capture"/>
<cocoon:plugin name="cordova-plugin-media"/>
<cocoon:plugin name="cordova-plugin-file"/>
<cocoon:plugin name="cordova-plugin-device"/>

重要的是要注意我刚安装这些插件才能获得想要的权限,但我根本就没有使用它们。

It's important to note that I just installed these plugins in order to obtain the wanted permissions, but I am not using them at all.

可能更有经验的开发人员会有更好的解决方案,但是,现在,这是我找到解决这个问题的最好方法。

Probably, more experienced developers will have better solutions but, for now, this is the best way I found to solve this problem.

这篇关于在Phonegap应用程序上使用相机,只有HTML输入,没有Camera API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 04:48