Skip to content

android error when select one image not multiple

I am trying to get images from my Gallery and upload them to the server. I want to allow the user to select multiple images from gallery. when I select two or more images it works very well. But when I select one image only it ignore it and return nothing. Here is my code and I am printing message when no clip Data is null

public void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (requestCode == 10 && resultCode == Activity.RESULT_OK) {

                ClipData clipData = data.getClipData();

                if (clipData != null) {
                    bitmaps_group=new Bitmap[clipData.getItemCount()];
                    for (int i = 0; i < clipData.getItemCount(); i++) {

                        ClipData.Item item = clipData.getItemAt(i);
                        Uri uri = item.getUri();

                        try {
                            bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), uri);
                            bitmaps_group[i]=MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), uri);

                        } catch (IOException e) {
                    new Encode_image().execute();



here where i call open the gallery:

imageView.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        System.out.println("r1 clikcid");

        Intent intent = new Intent();
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
        startActivityForResult(Intent.createChooser(intent,"Select Picture"), 10);


If only one image is selected it will not be in ClipData as is the case with selecting more images.

Instead data.getData() will be the Uri of the selected one.