Finally, I got a solution. When using EXTRA_ALLOW_MULTIPLE , when there is more than one content that the user selects, instead of returning to intent.getExtra() , the data from the intention is returned to ClipData , which is only supported for SDK versions 18 and higher. From there, the data can be obtained using the following code β
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) && (null == data.getData())) { ClipData clipdata = data.getClipData(); for (int i=0; i<clipdata.getItemCount();i++) { try { Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), clipdata.getItemAt(i).getUri()); //DO something } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
I put a null check for intent.getData() , because in the case of a single image, data is accepted in intent.getData() , and in the case of multiple selection, it is taken as null .
So, for sdk versions below 18 and for a single selection (regardless of sdk version) the data can simply be obtained as follows:
InputStream ist = this.getContentResolver() .openInputStream(data.getData()); Bitmap bitmap = BitmapFactory.decodeStream(ist);
Prateek
source share