How to invoke the default file chooser picker in Android?

Lipis picture Lipis · Jun 7, 2012 · Viewed 9.1k times · Source

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.

Answer

CommonsWare picture CommonsWare · Jun 7, 2012

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