我尝试从相册选择多张图片,但是我只发现了选择单个图片的方法。
@请查看此处 https://dev59.com/7W445IYBdhLWcg3wuslT#15029515
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1);
有没有一种方法可以选择多张图片?我尝试从相册选择多张图片,但是我只发现了选择单个图片的方法。
@请查看此处 https://dev59.com/7W445IYBdhLWcg3wuslT#15029515
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1);
有没有一种方法可以选择多张图片?首先,您需要在photoPickerIntent中使用putExtra函数
photoPickerIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE);
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 呢?您将收到一组 URI。
就像这样:
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.
}
}