Question

So I'm trying to allow the user to pick a particular piece of media with my Android Application using the method described here: Access pictures from Pictures app in my android app

It works great, except for the fact that I can seemingly only choose between either Video or Photo to present the user with, not both at the same time. Is there a good way to do this with:

startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), SELECT_IMAGE);

Thanks!

Was it helpful?

Solution

I've used this several times. The best way is something like:

Intent mediaChooser = new Intent(Intent.ACTION_GET_CONTENT);
//comma-separated MIME types
mediaChooser.setType("video/*, images/*");
startActivityForResult(mediaChooser, 1);

Even if this isn't perfectly accurate, it has worked fine in everything I've used it in. It will open up a Gallery-esque activity with a thumbnail list of every picture/video in the user's gallery. The returned intent to onActivityResult() has an extra called "DATA" which will be a content:// URI to the selected media.

EDIT: oops, to get the URI to the selected media you actually want to call getData() on the Intent that gets passed to onActivityResult()

OTHER TIPS

Kivy - The easiest way is to create an intent to select a piece of media and restrict it to video:

Intent pickMedia = new Intent(Intent.ACTION_GET_CONTENT);
pickMedia.setType("video/*");
startActivityForResult(pickMedia,12345);

Note - 12345 is the integer that your app needs to listen for on a request callback so that you can send whatever info you receive wherever you need to.

You then need to also have that same activity listening for the info to be sent back from that intent:

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 12345) {
            if (resultCode == Activity.RESULT_OK) {
                Uri selectedVideoLocation = data.getData();

                // Do something with the data...
            } 

        }
    }

Cool?

intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 1);

Try this

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, 101);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top