在只有 HTML 输入的 Phonegap 应用程序上使用相机,没有相机 API [英] Using camera on Phonegap app with only HTML input, without Camera API

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

问题描述

是否可以仅使用 HTML 输入在 phonegap 应用程序中从相机获取照片,而无需使用相机 API?

场景

我开发了一个应用,并通过Phonegap进行封装(Build)

用户可以使用html文件输入提交照片.但是没有选择从相机拍摄新照片,只有图库和文件(以及任何其他存储应用,如驱动器或保管箱,如果是这样的话).

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

解决方案

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

<小时>

1.捕获"属性(来自 Raymond Camden post)

使用这种方法,您所要做的就是像这样添加捕获"属性:

Raymond 解释说,使用这种方法您不需要使用 PhoneGap 的相机 API,因为 Google 开发了此选项并在 Google IO 演示,并且根据 Google 开发人员和 Raymond 的说法,它有效.

但是……不适合我.

<小时>

2.配置 Phonegap 以询问相机的许可(来自 Jorge Lizaso 的问题)

可能是因为您的应用没有适当的权限,所以没有显示相机选项"

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

我已经尝试过方法 2 和 4,虽然我的应用程序现在要求获得相机许可并且我正确地允许它,但是当我使用文件输入时,所有选项(如画廊和文件)都显示出来,但没有相机.

<小时>

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

由于我的 android webview 可能会过时(并且与解决方案 #1 不兼容),我决定在我的应用程序中包含最好的 webview:最新版本的 Google Chromium.

但是……没有再成功.

<小时>

1、2 和 3 组合

结果:没有……成功.

解决方案

是的,有一个解决方案,不需要 Cordova/PhoneGap 的 Camera API.

出于我不知道的原因,CocoonJS(名为 WebView+)中使用的 webkit 更加优化和比 phonegap 的 Crossswalk 更适合 HTML5 应用(拜托,我与 Cocoon 无关).

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

<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"/>

重要的是要注意,我只是安装了这些插件以获得所需的权限,但我根本没有使用它们.

<小时>

可能更有经验的开发人员会有更好的解决方案,但就目前而言,这是我找到的解决此问题的最佳方法.

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

Scenario

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

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

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

Solutions

I've tried the following solutions without success:


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

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

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

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 (and 1). Use the latest version of webkit with Crosswalk to ensure solution #1

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 and 3 combined

The result: no... success.

解决方案

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

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

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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆