简体   繁体   English

通过HTML5或JavaScript启动Android手机前置摄像头

[英]Launch Android phone front camera by HTML5 or JavaScript

I am building a web app which should open the front camera in the phone with Android (version 4.0+) and after taking the picture the app should upload captured image to my own server. 我正在构建一个Web应用程序,该应用程序应在Android(4.0及更高版本)的手机中打开前置摄像头,拍照后,该应用程序应将捕获的图像上传到我自己的服务器上。

So is it possible to launch Android phone's front camera by any HTML5 tag or JavaScript code? 那么有可能通过任何HTML5标签或JavaScript代码启动Android手机的前置摄像头吗?

I know that rear camera is possible to launch with this tag: 我知道可以使用此标签启动后置摄像头:

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

But how about front camera? 但是前置摄像头怎么样? Furthermore, is it possible to add fixed size focus frame to the camera view by using HTML5 web app? 此外,是否可以使用HTML5 Web应用程序将固定尺寸的对焦框添加到相机视图?

For clarity: Web app is simply the website in my case. 为了清楚起见:就我而言,Web应用程序只是网站。 It is not any Android app written with PhoneGap or something like that. 它不是任何使用PhoneGap或类似工具编写的Android应用。

Use Device Camera without using PhoneGap or Android Native code 在不使用PhoneGap或Android本机代码的情况下使用设备相机

As per I understand you don't want to use PhoneGap for the mobile website but you want to use the native camera option. 据我了解,您不想为移动网站使用PhoneGap,但您想使用本机摄像头选项。

In this scenario what I can suggest is you can use Bridgeit which can help you to access the native camera option. 在这种情况下,我建议您可以使用Bridgeit ,它可以帮助您访问本机摄像头选项。 Click on the link to check for the demo. 单击链接以检查演示。

It is very simple to use. 使用非常简单。 You need to add a .js file in your HTML page and call the camera method to access the native camera option of the device. 您需要在HTML页面中添加.js文件,然后调用camera方法来访问设备的本机照相机选项。

Sample code: 样例代码:

Use the Bridgeit.js in the HTML header... 在HTML标头中使用Bridgeit.js ...

<script type="text/javascript" src="http://api.bridgeit.mobi/bridgeit/bridgeit.js"></script>

after that you can call the device camera using the following code: 之后,您可以使用以下代码调用设备摄像头:

bridgeit.camera( 'myId', callback, {postURL: '/upload'});

For more detail click on Bridgeit . 有关更多详细信息,请单击Bridgeit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM