如何在android中使用intent进行图像选择来获取图像计数

如何在android中使用intent进行图像选择来获取图像计数,android,kotlin,Android,Kotlin,当我从gallery的“照片”文件夹中选择多张图像时,只加载了一张图像。如何解决这个问题。我能得到图像计数吗 if(data.getData() != null ) { val imagePath = data.getData().getPath() } @覆盖 ActivityResult上的公共void(int请求代码、int结果代码、意图数据){ supe

当我从gallery的“照片”文件夹中选择多张图像时,只加载了一张图像。如何解决这个问题。我能得到图像计数吗

            if(data.getData() != null ) 
                 {

                val imagePath = data.getData().getPath()


                  }
@覆盖
ActivityResult上的公共void(int请求代码、int结果代码、意图数据){
super.onActivityResult(请求代码、结果代码、数据);
if(requestCode==选择图片){
if(resultCode==Activity.RESULT\u确定){
if(data.getClipData()!=null){
int count=data.getClipData().getItemCount();//在for循环之前计算计数——否则,每次循环都计算计数。
for(int i=0;i
 @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode == SELECT_PICTURES) {
        if(resultCode == Activity.RESULT_OK) {
            if(data.getClipData() != null) {
                int count = data.getClipData().getItemCount(); //evaluate the count before the for loop --- otherwise, the count is evaluated every loop.
                for(int i = 0; i < count; i++)  
                    Uri imageUri = data.getClipData().getItemAt(i).getUri();
                    //do something with the image (save it to some directory or whatever you need to do with it here) 
                }
            } else if(data.getData() != null) {
                String imagePath = data.getData().getPath();
                //do something with the image (save it to some directory or whatever you need to do with it here)
            }
        }
    }
}