Launch Android phone front camera by HTML5 or Java

2019-06-05 00:45发布

问题:

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.

So is it possible to launch Android phone's front camera by any HTML5 tag or JavaScript code?

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?

For clarity: Web app is simply the website in my case. It is not any Android app written with PhoneGap or something like that.

回答1:

Use Device Camera without using PhoneGap or Android Native code

As per I understand you don't want to use PhoneGap for the mobile website but you want to use the native camera option.

In this scenario what I can suggest is you can use Bridgeit which can help you to access the native camera option. 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.

Sample code:

Use the Bridgeit.js in the HTML header...

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