Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Videos AND Photos on Android 1.5 +

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!

like image 703
FunnyLookinHat Avatar asked Dec 07 '09 22:12

FunnyLookinHat


People also ask

Where are photos and videos stored on Android?

Your photos will be in one of two areas: The Pictures folder or the DCIM folder. Photos you took with your phone will likely be in your DCIM folder, while other photos or images (like screenshots) you keep on your phone will likely be in the Pictures folder.

Why can't I see my pictures in my gallery Android?

If your photos are visible in My Files but are not in the Gallery app, these files may be set as hidden. This prevents Gallery and other apps from scanning for media. To solve this, you can change the option for showing hidden files.


3 Answers

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()

like image 61
Robert Avatar answered Sep 23 '22 00:09

Robert


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?

like image 45
FunnyLookinHat Avatar answered Sep 23 '22 00:09

FunnyLookinHat


intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 1);
like image 23
michkra Avatar answered Sep 23 '22 00:09

michkra