开发者

Select multiple images from Photo Gallery on Android using Intents

开发者 https://www.devze.com 2023-02-05 12:02 出处:网络
@See this https://stack开发者_开发技巧overflow.com/a/15029515/185022 I`m trying to select images from gallery, but i only found the way to select a single image.

@See this https://stack开发者_开发技巧overflow.com/a/15029515/185022

I`m trying to select images from gallery, but i only found the way to select a single image.

Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1);

Is there a way to select multiple images?


Create a custom gallery same like: Android custom image gallery with checkbox in grid to select multiple


First of all you need to use putExtra with your photoPickerIntent

photoPickerIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE);

Then in your on activity result you should get ClipData from Intent like this

ClipData clipData = data.getClipData();
//Where data is param intent of onActivityForResult

And iterate this clipData to get URI for specific picked image.

for (int i = 0; i < clipData.getItemCount(); i++){
    Uri uri = clipData.getItemAt(i).getUri();
}

I hope this helps


Why don't you try ACTION_SEND_MULTIPLE thing. You will receive a set of Uris.

Something like

    if (Intent.ACTION_SEND_MULTIPLE.equals(action))
        && Intent.hasExtra(Intent.EXTRA_STREAM)) {
        ArrayList<Parcelable> list =
    intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        for (Parcelable parcel : list) {
           Uri uri = (Uri) parcel;
           /// do things here.
       }
    } 

Saw this code block on a google-groups post. Just try this out. Thanks.


I think, you should implement custom gallery for multiple image pick action.

see here in details.

0

精彩评论

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