如何使用java从图库中选择多个图像。 我有使用此代码但没有发生错误 并且无法从图库中选择图像。 这是我的代码:
mainactivity.java
//button On Click:
{
Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
final int ACTIVITY_SELECT_IMAGE = 1234;
startActivityForResult(i, ACTIVITY_SELECT_IMAGE);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data){
//super.onActivityResult(requestCode,resultCode,data);
switch(requestCode) {
case 1234:
if(resultCode == RESULT_OK){
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
/* Now you have choosen image in Bitmap format in object "yourSelectedImage". You can use it in way you want! */
}
}
}
});
它无法正常工作。我无法选择图片。
答案 0 :(得分:0)
@Drashti Kapadia:您可以使用Android开源库MultipleImagePick。它使用Universal image loader library进行异步加载和缓存。
答案 1 :(得分:0)
尝试以下代码。希望这有帮助!
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); // allow the user to select multiple items, only available in Android API 18 and higher.
startActivityForResult(intent, requestCode);