4

If you go to imgur.com from your Android device, click on Upload an Image and then on Touch here to select your images, the Android prompts you with a Choose file for upload with few options. The good thing about this picker is that even if there is no camera as an option (for older phones) you can start the camera from the Gallery application, take a picture and eventually select it from the gallery to be uploaded.

That works also for any file <input> on any website.

So my question is: how can I invoke that file picker and eventually get the path to the selected image in native Java app?

If possible I would like to filter it so it will prompt only for images and not audio files and I don't want to install any file managers since it's doable within the browser. It's hard to believe that is available only for the Browser.

I don't want to implement my own file browser or list the camera's folder within my app. I'm also just starting with Android so a complete example to get eventually the file path or an image would be awesome.

imz -- Ivan Zakharyaschev
  • 4,921
  • 6
  • 53
  • 104
Lipis
  • 21,388
  • 20
  • 94
  • 121
  • Are you asking for an HTML5 Web app (in a place where you don't want to use ``), or for a native Java app? – CommonsWare Jun 06 '12 at 22:44
  • @CommonsWare Native Java app... in HTML5 it's obvious.. just use the `` – Lipis Jun 06 '12 at 22:49
  • @CommonsWare maybe the tag file-upload is misleading, but I didn't know what to add ;) Feel free to edit as needed.. – Lipis Jun 06 '12 at 22:51
  • 2
    **Careful about assumptions** on many (I dare say most at present) android devices, your example does not result in an opportunity to pick a *file* but rather only in opportunities to pick an application to provide something such as an *image*. Only if the user has installed a file manager app, or the device atypically came with one, or you have some potential recently featureful android build will this get you the ability to actually pick a *file*. – Chris Stratton Jun 06 '12 at 23:25

1 Answers1

4

Based on the chooser that comes up, <input> would appear to be requesting an ACTION_GET_CONTENT activity, with a MIME type of */*.

If possible I would like to filter it so it will prompt only for images and not audio files

Use a MIME type of image/*.

I'm also just starting with Android so a complete example to get eventually the file path or an image would be awesome.

See: https://stackoverflow.com/a/10274699/115145

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • @Lipis: BTW, it dawned on me that I have a more complete example of `ACTION_GET_CONTENT` here: https://github.com/commonsguy/cw-omnibus/tree/master/Camera/Content – CommonsWare Jun 07 '12 at 00:04
  • Pretty straight forward.. Nice one.. I might use it as well to get an image directly from a Camera. – Lipis Jun 07 '12 at 00:15
  • It worked like a glove..!! I also managed to go all the way and upload it after going through this answer: http://stackoverflow.com/a/3801665/8418 – Lipis Jun 07 '12 at 01:48
  • Do you know if it's possible to get multiple files from that chooser? You can definitely choose many files from the Gallery application.. but is it possible to ask for more than file.. or it has to be done the either way around.. choose files and then share on your app..? – Lipis Jun 07 '12 at 05:37
  • 1
    @Lipis: "Do you know if it's possible to get multiple files from that chooser?" -- no, only one. "choose files and then share on your app" -- that direction uses `ACTION_SEND` (one) or `ACTION_SEND_MULTIPLE` (more than one). – CommonsWare Jun 07 '12 at 10:47