maximum image selection limit from gallery Android

bubu uwu picture bubu uwu · Nov 9, 2015 · Viewed 8.1k times · Source

I am trying to get image's Uri in the Gallery built-in app from inside my application.

so, I was using the Intent below, but it selected many more image.

i want to set limitation. less than 3

@Override
public void onClick(View v) {
    Intent intent = new Intent( );
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    startActivityForResult(Intent.createChooser(intent, "select images"), PICK_IMAGE_MULTIPLE);
}

how do i fix this.

Do you have any suggestions?

Answer

Daniël van den Berg picture Daniël van den Berg · Nov 9, 2015

Unfortunately, as stated by http://developer.android.com/reference/android/content/Intent.html#EXTRA_ALLOW_MULTIPLE, this is not possible.

This is a boolean extra; the default is false. If true, an implementation is allowed to present the user with a UI where they can pick multiple items that are all returned to the caller.

You'll have to manually check the returned data to see if it's more than 3 items, and if so, show a Toast and let them try again.