Kiara_2013
Kiara_2013

Reputation: 171

Camera capture using Html5 input tag

I am using the below line of code in order to invoke camera from my web application.

<input type="file" id="capture" accept="image/*; capture=camera" style="visibility:hidden;">

Using this, I am able to get the pop up with options of "Choose existing photo" and "Take Picture", when the application is opened in iOS6. But I want to open up camera capture directly rather then getting this pop up and then select "Take Picture" option.

Thanks in advance.

Upvotes: 17

Views: 23807

Answers (3)

Tim
Tim

Reputation: 1826

What browser are you using on Android? This page indicates that it doesn't work on Chrome but should work on the Android browser and on iOS Safari. It doesn't specifically mention Chrome for Android. I tested the tag with the Chrome browser on my LG G6 phone and it didn't work. I wasn't able to test Android browser--it seems to be missing on my phone.

https://caniuse.com/#feat=html-media-capture

Upvotes: 0

Ian G
Ian G

Reputation: 5526

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

Works in Chrome on Android (at least).

Upvotes: 9

tagawa
tagawa

Reputation: 4611

I'm afraid this is not possible as per the specification for security/privacy reasons:

The user agent SHOULD NOT enable any device for media capture, such as a microphone or camera, until a user interaction giving implicit consent is completed.

http://www.w3.org/TR/capture-api/#security

An alternative is to use getUserMedia. This still shows a dialog requesting user permission but in some browsers the user can choose to hide it after granting access to a domain.

Upvotes: 1

Related Questions