Can you launch the native Camera App from an Html 5 Web App?
Asked Answered
J

3

40

I have a mobile website that allows users to upload photos using the file input type (Browse button). If possible, I would like to launch the Camera App of an Android device on click of the Browse button or any other HTML button. Is this possible?

I read this similar post but in their example they are asking how to register the Camera App as Intent Receiver for uploading images. Similar to that, I just want to launch the Camera App in the same way the Android browser picks up on Phone Number and Addresses.

Joellyn answered 6/10, 2011 at 14:45 Comment(0)
L
52

Android 3.0 Honeycomb added Device API support. Google I/O 2011 presentation shows an example on slide 30:

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

It also points to a test site that not surprisingly does not do much on my Froyo phone.

Anybody with a tablet tried it and can tell us what it does and does not do?

4.0 Icecream Sandwich was announced. Code drop may not happen for several months or longer and actual devices may show in the market around Christmas. As to Icecream on current generation of Froyo / Gingerbread phones, official ODM/carrier 4.0 releases will never happen? I'd love to be proved wrong on this. Any word from custom ROMs community?

Lout answered 18/10, 2011 at 18:19 Comment(5)
Just tried it on my Honeycomb tablet. When you press the button, the camera application starts, allowing you to take a picture. An "OK" button appears once the picture is taken, and if you press it, you'll get back to the website and the photo appears in the black rectangle.Vatican
@Michell Pretty cool! A couple of other defined selectors are accept="video/*;capture=camcorder" accept="audio/*;capture=microphone" W3C spec defaults to capture=filesystem Wanna try those as well, please?Lout
I've marked this as the answer because it seems to work on 3+, but it does not work as expected on 2.3. At least not the ROM I am using. Thanks @WalterKarshatJoellyn
On Android 4.3, this let me select the camera or other capture options, but only user2777963's answer actually brought me directly to the camera app.Plosion
@Plosion which answer allowed you open camera app directly. my web app in android also opens image chooser with all gallery options along with camera. I just need to open direct camera in android.Anneal
C
28

I tried this:

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

from here: https://coderwall.com/p/epwmoa

With my Galaxy S2 phone (on Chrome).

It's working and open directly the camera.

Combatant answered 27/9, 2013 at 11:31 Comment(2)
I think so but I didn't try recently. Can you try with this link ? codepen.io/anon/pen/wNBMNeCombatant
Tested it with android 10 and it did the job!Jacklyn
A
2

if someone need, i'm using the confirmed answer on asp.net. i added to asp.net control the attributes accept="image/*" capture="camera"

<asp:FileUpload ID="FileUpload1" runat="server" type="file" accept="image/*" capture="camera" />
<asp:ImageButton ID="bt_AttUp" runat="server" onClick="bt_AttUp_Click" />

and on .net server side

FileUpload1.SaveAs("PathDestination")
Australian answered 16/9, 2021 at 9:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.