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.

3 Answers 3

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?

5
  • 1
    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. Commented Oct 26, 2011 at 21:21
  • 2
    @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?
    – Walter K
    Commented Oct 27, 2011 at 20:29
  • 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 @WalterKarshat
    – shanabus
    Commented Feb 13, 2012 at 14:28
  • 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. Commented Oct 21, 2013 at 3:12
  • @gatoatigrado 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. Commented May 10, 2019 at 1:17
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.

2
  • I think so but I didn't try recently. Can you try with this link ? codepen.io/anon/pen/wNBMNe
    – paaacman
    Commented Jan 22, 2019 at 21:37
  • 1
    Tested it with android 10 and it did the job!
    – Sloomy
    Commented Mar 20, 2021 at 7:42
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")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.