我想使用 Intent.EXTRA_ALLOW_MULTIPLE 从移动相册中选择多个图像。它在 Google photoes 中工作正常。但我无法在图库的相册文件夹中选择多个图像,所以我应该怎么做,我的代码在下面给出..
这是 图片
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
{
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.putExtra(intent.EXTRA_ALLOW_MULTIPLE, true);
intent.putExtra(intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(intent, 2);
}
}catch (Exception e){
Toast.makeText(MainActivity.this, e.toString(), Toast.LENGTH_SHORT).show();
}
活动结果:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// When an Image is picked
if (requestCode == PICK_IMAGE_MULTIPLE && resultCode == RESULT_OK && null != data) {
// Get the Image from data
if (data.getClipData() != null) {
ClipData mClipData = data.getClipData();
int cout = data.getClipData().getItemCount();
for (int i = 0; i < cout; i++) {
// adding imageuri in array
Uri imageurl = data.getClipData().getItemAt(i).getUri();
mArrayUri.add(imageurl);
}
// setting 1st selected image into image switcher
imageView.setImageURI(mArrayUri.get(0));
position = 0;
} else {
Uri imageurl = data.getData();
mArrayUri.add(imageurl);
imageView.setImageURI(mArrayUri.get(0));
position = 0;
}
} else {
// show this if no image is selected
Toast.makeText(this, "You haven't picked Image", Toast.LENGTH_LONG).show();
}
}
}