一度に複数の画像をアップロードできる画像アップローダーを作成しています。
galerijButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
}
});
...
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case SELECT_PHOTO:
if(resultCode == RESULT_OK){
if(imageReturnedIntent.getData() != null){
//If uploaded with Android Gallery (max 1 image)
Uri selectedImage = imageReturnedIntent.getData();
InputStream imageStream;
try {
imageStream = getContentResolver().openInputStream(selectedImage);
Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream);
photos.add(yourSelectedImage);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} else {
//If uploaded with the new Android Photos gallery
ClipData clipData = imageReturnedIntent.getClipData();
for(int i = 0; i < clipData.getItemCount(); i++){
clipData.getItemAt(i);
//What now?
}
}
}
break;
....
選択したすべての画像を写真配列に追加したいと思いますArrayList<Bitmap>
。ClipData.Item
どういうわけか、をに変換する必要Bitmap
がありますが、どうすればよいですか?