android - getClipData() returning null when a single image is selected when working fine when multiple images are selected
问题描述
基本上,我需要选择多个图像。当我选择多个图像时,我的代码工作正常,但当我选择单个图像时它不起作用。
我正在使用此代码来选择图像
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);
}
我的 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();
}
}
}
当我选择多个图像时,我的代码工作正常。但是当我选择单个图像时, data.getClipData() 返回 null。我基本上需要所有选择图像的 URI 列表。我不明白这个问题。另外,string.valueof(数据)显示选择一个图像时存在URI,但是data.getClipdata()仍返回null。
解决方案
此外, String.valueof(data) 显示选择一个图像时存在 URI,但 data.getClipData() 仍返回 null
你会Uri
从电话中得到,交付到data.getData()
哪里。data
Uri
onActivityResult()
推荐阅读
- visual-c++ - 无法将变量添加到编辑控件,错误:“对象引用未设置为对象实例”
- c# - QueryAsync DynamoDB with Index (Partition Key and Short Key) .Net Core
- php - Laravel 在任何事情后重定向
- python - 如何从可以使用 sklearn-pmml-model 导入 python 文件的 sklearn 模型创建 pmml?
- protractor - 如何使用 jasmin 开始量角器自动化
- mysql - 将 blob 数据类型值插入 mysql 表时出错
- php - 在 PHP 中,如果我希望每个用户都拥有我想要保留的唯一数据,并且只在他们登录时加载,我该怎么做?
- pandas - 保留具有最新日期的行以匹配 ID。删除所有具有旧日期的行以匹配 id
- sql - Oracle:具有散列集群的多块读取对象
- vb.net - vb.net如何创建登录权限