3

In my open source app, I want to let users insert a picture/video/sound/etc. The user can either select an existing media from the SD card or use the device's hardware (take a photo, record a video, record a sound, draw on touchscreen) if they prefer to create a new media.

There are plenty of code snippets showing how to implement each of these things, but rather than re-inventing the wheel, is there a library that handles the whole activity of choosing a media file? I would just call this library, it would handle the UI, and return me the filepath to the media the user selected/created.

Here is how it could look like:

Android media chooser

I am sure many apps would find this widget useful (CMS authoring, wysiwyg, sharing apps, rich chat, ...). As an LGPL (or public domain) component, I am sure it would be popular and gather a community of developers. Before I launch this project, is there already such a gadget?

Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
  • As I searched but couldnt find such jar but found all required snippets so,Just suggestion Nicolas, I just wonder that why dont you go and collect all the snippets required to get media from sdcard or record or capture new files, which are surely available on internet in different blogs [May be you can find all the code in StackOverflow answers only.!] Then you will need to make only different Java file/Methods for each and once test that using ExampleActivity..and then Export all that java files as jar and then you will have your own jar to do the tasks. – MKJParekh Jun 12 '12 at 07:28
  • @FasteKerinns: If the gadget I described exists already, it would be much smarter to use it, rather than gathering random snippets and making sure they work on all recent Android versions (which takes much more time than one might think). Rather collaborate than re-invent the wheel :-) I would be surprised if such a gadget does not already exists. – Nicolas Raoul Jun 12 '12 at 08:01
  • 1
    Yeh reading your question i am also trying to search for the same, will send you the link if i get any one. – MKJParekh Jun 12 '12 at 08:45

3 Answers3

3

For taking a picture, use this Intent:

Intent intent = new Intent( android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
startActivityForResult(intent);

For taking video, use this Intent:

Intent intent = new Intent( android.provider.MediaStore.ACTION_VIDEO_CAPTURE );
startActivityForResult(intent);

For recording audio, use this Intent:

Intent intent = new Intent( android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION );
startActivityForResult( intent );

You, of course, would have to design the Activity to pick which action they would like to perform. See the linked documentation for retrieving the file path when the Activity returns.

Jason Robinson
  • 31,005
  • 19
  • 77
  • 131
  • If the gadget I described in my question exists already, it would be much smarter to use it, rather than gathering random snippets and making sure they work on all recent Android versions (which takes much more time than one might think). Rather collaborate than re-invent the wheel :-) I would be surprised if such a gadget does not already exists. – Nicolas Raoul Jun 13 '12 at 01:59
  • What do you mean by "gadget"? Using these action intents means you use the built-in apps for performing these functions, thus avoiding reinventing the wheel. – Jason Robinson Jun 13 '12 at 04:24
  • And all 3 action intents I've listed will work back to Cupcake, meaning they will work for [99.7%](http://developer.android.com/resources/dashboard/platform-versions.html) of devices. – Jason Robinson Jun 13 '12 at 04:26
  • Indeed, I reckon that these 3 actions are much cleaner than random snippets. I will use them if I have no choice but create my own media selection/creation activity. Thanks! – Nicolas Raoul Jun 13 '12 at 04:45
3

I wrote a small Android Library Project, called aFileChooser, that aims to streamline the selection part of this process. It includes a built-in file explorer, and returns a File object after selection. You can also retrieve the image or video thumbnail, and use helper methods to get the URI and path.

Disclaimer: I haven't had a chance to test this with ICS, but it should function properly.

https://github.com/iPaulPro/aFileChooser

Finding an all-in-one solution with capture may not be as easy, as this is one of the areas where fragmentation is real.

Paul Burke
  • 25,496
  • 9
  • 66
  • 62
  • Very nice! You are right that this is an area where fragmentation makes things difficult. Especially for testing. Making sure this patchwork of snippets is reliable on many devices takes a lot of time (maybe ~5 days per month). And that's exactly why I think collaboration is better than doing it alone. – Nicolas Raoul Jun 18 '12 at 05:42
  • 1
    Awarding bounty because I will use your library if I have no choice but create my own media selection/creation activity. But still hoping someone finds what I am looking for... – Nicolas Raoul Jun 19 '12 at 10:30
  • Reading your library made me understand that what I really need is a call to `Intent.ACTION_GET_CONTENT`. That will let the user choose an image from the gallery, record a sound, etc depending on which apps are installed. – Nicolas Raoul Sep 06 '12 at 08:24
2

OI File Manager for Android is an open file manager that seamlessly cooperates with other applications http://www.openintents.org/en/node/159

potter
  • 281
  • 1
  • 3
  • Its PICK_FILE intent is indeed something that could be used if I wanted to have only "Pick file from the SD card", but my question is about an activity that would also allow the user to take a picture/video/sound if they want, rather than selecting an existing file. – Nicolas Raoul Aug 31 '11 at 12:29
  • @NicolasRaoul You did say OR (and actually made it bold). – Paul Burke Jun 16 '12 at 04:06
  • I meant the user can either select an existing file OR create a new one. User can choose. Sorry if it was unclear, I make it more explicit. – Nicolas Raoul Jun 18 '12 at 01:28