基本上,我需要选择多个图像。当我选择多个图像时,我的代码工作正常,但当我选择单个图像时,它不起作用。
我正在使用此代码来选择图像
public void getPhotoFromGallery(){
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"), 1);
}
Run Code Online (Sandbox Code Playgroud)
我的 onActivityResult() 是
super.onActivityResult(requestCode, resultCode, data);
Log.i("onActivityResult: ", "STARTED");
if(requestCode == 1 && resultCode == RESULT_OK && data!=null){
try {
Log.i("Error: ", String.valueOf(data));
ClipData mClipData = data.getClipData();
Log.i("Error: ", String.valueOf(mClipData));
.....
.....
}
catch (Exception e){
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我选择多个图像时,我的代码工作正常。但是当我选择单个图像时,data.getClipData() 返回 null。我基本上需要所有选定图像的 URI 列表。我不明白这个问题。此外,String.valueof(data) 显示当选择一张图像时存在 URI,但 data.getClipData() 仍返回 null。
android ×1