title: Android Image Picker Select multiple images from gallery with a maximum limit of 5
body: <p>I have an app where the user needs to be able to choose multiple pictures to send them somewhere. However, they can only send five images at a time. I need to be able to limit the number of images that they can pick from the gallery through the Image Picker. </p>
  
  <p>To put it in a single sentence: <strong>I want to limit the number of images/photos that the user can select in the default image selector from the gallery</strong>.</p>
  
  <p>Here is the code that I am using for my image picker:</p>
  
  <pre><code>Intent chooseIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  chooseIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
  startActivityForResult(chooseIntent, 2);
  </code></pre>
  
  <p>It already keeps track of how many images are selected at the top by default:</p>
  
  <p><img src="https://i.stack.imgur.com/IHDIO.png" alt=""></p>
  
  <p>Is there a way to set a maximum limit? Like to have a user only be able to select up to 5 images. </p>