gpt4 book ai didi

android - 如何从Android图库中选择多张图片

转载 作者:行者123 更新时间:2023-11-30 02:09:54 25 4
gpt4 key购买 nike

private static final int PICK_FROM_GALLERY = 2;    
private void fireGallerypick() {
Intent intent = new Intent();
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_FROM_GALLERY);
}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case PICK_FROM_GALLERY:
if (resultCode == -1) {
System.out.println("Gallery pick success");
String[] all_path = data.getStringArrayExtra("all_path"); //But it returns null
break;
}
}
}

当我完成选择时,我可以选择多张图片。我需要 String[] 中所有选定文件的路径。提前致谢。

最佳答案

Intent i = new Intent(Action.ACTION_MULTIPLE_PICK);
startActivityForResult(i, 200);

要在 onActivityResult 中获取图像路径,请这样做 -

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 200 && resultCode == Activity.RESULT_OK) {

String[] all_path = data.getStringArrayExtra("all_path");



for (String string : all_path) {

String sdcardPath = string;


}

注意:EXTRA_ALLOW_MULTIPLE 选项仅在 Android API 18 及更高版本中可用。

关于android - 如何从Android图库中选择多张图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30252078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com