在Phonegap上使用摄像头仅使用HTML输入构建,无需使用Camera API [英] Using camera on Phonegap Build only with HTML input, without Camera API

查看:150
本文介绍了在Phonegap上使用摄像头仅使用HTML输入构建,无需使用Camera API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在手机应用程式中使用HTML输入功能从相机中取得相片,而无需使用Camera API?



场景 p>

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



照片使用html文件输入。但是没有选择从相机拍摄新照片,只有图库和文件(以及任何其他存储应用程序,如驱动器或Dropbox,如果是这样)。



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



解决方案



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






捕获属性(来自 Raymond Camden post < a>)



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

 < input type =filecapture =cameraaccept =image / *id =JustChooseAnID> Raymond解释说,使用这种方法,你不需要使用PhoneGap的Camera API,因为Google开发了这个选项并在 Google IO简报中显示,并根据Google开发人员和还有Raymond,它工作。



但是..不适合我。





$ b b

2。配置Phonegap请求相机的权限(来自 Jorge Lizaso的问题



也许相机选项没有显示,因为您的应用没有正确的权限





我已经尝试过方法2和4,虽然我的应用程序现在询问对于相机权限,我允许它正确,当我使用文件输入,所有的选项被提出(像画廊和文件),但没有相机。






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



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



但是没有成功。






1,2和3组合



结果:no ... success。

解决方案

是的,有一个解决方案,而不需要Cordova / PhoneGap的Camera API。 / p>

由于我不知道的原因,用于 CocoonJS



我完全放弃了我的Phonegap config.xml设置,并且调整了HTML5应用程序(请注意,试过茧生成器。我使用解决方案#1(文件输入中的捕获属性)并通过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/>

请注意,我刚刚安装这些插件,






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


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 Crosswalk used in CocoonJS (named WebView+) is far more optimized and adjusted to HTML5 apps (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.

这篇关于在Phonegap上使用摄像头仅使用HTML输入构建,无需使用Camera API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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