How to limit multiple image selection from the gallery?

32
January 11, 2019, at 10:20 PM

I have implemented adding multiple image selection from the gallery in my project. However, I want to limit the user so he/she can select only 3 images from the gallery.

I have implemented selecting multiple images from the gallery like this:

 `Intent intent = new Intent();
        intent.setType("image/*");
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select Picture"), 1);`

How can I achieve this?

Thanks.

Answer 1

This is not possible. https://developer.android.com/reference/android/content/Intent.html#EXTRA_ALLOW_MULTIPLE

You'll have to manually check the returned data to see if it's more than 10 items, and if so, show a Toast

Answer 2

put this in your build.gradle(app)

 compile 'com.github.esafirm.android-image-picker:imagepicker:1.5.0'
compile 'com.github.esafirm.android-image-picker:rximagepicker:1.5.0' 

and this in your activity

private void pickImage() {
    ImagePicker.create(UploadPhotosActivity.this)
            .showCamera(false)
            .limit(3)
            .imageTitle(getString(R.string.select_image))
            .folderTitle(getString(R.string.folder))
            .theme(R.style.ImagePickerTheme)
            .start(RC_CODE_PICKER);
} 
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
     if (requestCode == RC_CODE_PICKER) {
            Log.d("===uploadPhoto", "gallery : " + data);
            imagesList = (ArrayList<Image>) ImagePicker.getImages(data);
            Intent intent = new Intent(UploadPhotosActivity.this, ImageCropperActivity.class);
            intent.putExtra(ImageCropperActivity.EXTRA_VIEW_PORT_RATIO, imagesList);
            startActivity(intent);
        }
    } else {
        Intent returnIntent = new Intent();
        setResult(Activity.RESULT_CANCELED, returnIntent);
        finish();
    }
}
READ ALSO
How to put image on google map using groundoverlay in android where image having 5k (width)* 5k (height) and 1.6 mb of size?

How to put image on google map using groundoverlay in android where image having 5k (width)* 5k (height) and 1.6 mb of size?

I wanna put an image of my city which contains roads and homes on google map using groundoverlay method in android, where my image size and dimensions are very largeHow I can put this image on map in android?

40
Recycler view is not updating on realtime update

Recycler view is not updating on realtime update

i am trying to update recycler view when the user sends and removes friend requesti am using firebase firestore

48
Confusion in Geocoder Class

Confusion in Geocoder Class

I just want to launch my application which is using Reverse Geocoding with the help of Geocoder Class but I want to ask whether this cause any problem further?

35
where is the path of my react native static server

where is the path of my react native static server

I'm trying to run a static server in my app developed with react native, with the packages react-native-static-server and react-native-fs

50