簡體   English   中英

使用Intents從Android上的照片庫中選擇多個圖像

[英]Select multiple images from Photo Gallery on Android using Intents

@參見https://stackoverflow.com/a/15029515/185022

我試圖從圖庫中選擇圖像,但我只找到了選擇單個圖像的方法。

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

有沒有辦法選擇多個圖像?

創建一個自定義圖庫,例如: Android自定義圖庫,網格中有復選框以選擇多個

首先,您需要將putExtra與photoPickerIntent一起使用

photoPickerIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE);

然后在你的on活動結果中,你應該像這樣從Intent獲取ClipData

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

並迭代此clipData以獲取特定拾取圖像的URI。

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

我希望這有幫助

我認為,您應該為多個圖像選擇操作實現自定義庫。

詳見這里

你為什么不試試ACTION_SEND_MULTIPLE的事情。 你將收到一套Uris。

就像是

    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.
       }
    } 

在google-groups帖子上看到這個代碼塊。 試試吧。 謝謝。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM