I am trying to upload several pictures from my emulator, and this section of code works fine ( I can select couple pictures at the same time ) -
private void OpenGallery() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setType("image/*");
startActivityForResult(intent, REQUEST_IMAGE_GALLERY);
}
BUT, I can not understand how to implement the onActivityResult function. the data is correct but when I am trying to to data.getData() my emulator is shutting down. My onActivityResult function looks like this -
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_IMAGE_GALLERY) {
if (resultCode == RESULT_OK) {
try {
Log.d("TAG","DATA " + data); // I get data with 3 images for example
final Uri imageUri = data.getData(); // NOT WORKING
final InputStream imageStream =
getContext().getContentResolver().openInputStream(imageUri);
imageBitmap = BitmapFactory.decodeStream(imageStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
}
Any suggestions?