开发者

Accessing Videos AND Photos on Android 1.5 +

开发者 https://www.devze.com 2022-12-13 07:07 出处:网络
So I\'m trying to allow the user to pick a particular piece of media with my Android Applicatio开发者_StackOverflow中文版n using the method described here:

So I'm trying to allow the user to pick a particular piece of media with my Android Applicatio开发者_StackOverflow中文版n 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!


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


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消