Android pick limited number of images from gallery - android

I am using this piece of code to get multiple images from gallery:
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(Intent.createChooser(intent, getString(R.string.select_image)), GALLERY_CODE);
But how do I restrict the number of images that can be picked? For example, I only want the user to pick at most 9 images.

Related

How to load Images from Gallery in Recyclerview in android?

I am trying to Load Images from gallery into my application folder. I am using Recyclerview
By using this Intent i am able to select Multiple Images from Gallery but don't know how to get images in my applications folder. Note I have different folders in my application.
private void OpenFromGallery() {
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);`}
Hope it will works for you
Click here

ACTION_GET_CONTENT except image and video files in Android

If we have to get the image file from device then we have to write following code:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Choose Picture"), 1);
But what we have to do if we don't want to choose only image and video files.
I want that the file chooser window should show all the files except image and video.

How to pick multiple files from Android's gallery?

i need to open gallery and pick 1-n images OR 1-n videos (2 different intent) from Android's gallery, like the ACTION_PICK intent. How can I achieve that? There are some cool library on GitHub for multiple pick or custom gallery?
If you use API 18 or higher, you can add to your intent.putExtra like so:
Intent intent = new Intent();
intent.setType("image/*,video/*"); //For choosing both images and/or videos
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); //This should allow multiple selection
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), 1);
There is also a GitHub project to build your own GridView with multi selection
Read here
To pick multiple files from gallery you need to simply modify your intent. For example:
Intent i = new Intent();
i.setType("image/*");
i.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
i.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(intent,"Select"), 1);
Please note the i.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);

want video and library both in gallery in android

When picking a file from the Library, only photos are listed. Video files should also be shown.
Im Using this code
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),SELECT_PICTURE);
use following for pick both images and videos.
Intent mediaChooser =new Intent(Intent.ACTION_GET_CONTENT);
//comma-separated MIME types
mediaChooser.setType("video/*, images/*");
startActivityForResult(mediaChooser,IMAGE_PICK);

Picking images and videos on Android on 2.1 using ACTION_GET_CONTENT

I'm working on an app that needs to have the user select an image or video. On pre-2.1 devices, using ACTION_GET_CONTENT seems to work fine with multiple MIME types:
new Intent(Intent.ACTION_GET_CONTENT).setType("video/*, image/*")
However, on a Droid running 2.1, this gives a "There are no items in your collection". Using the same code with either "video/" or "image/" gives the desired result. Is there a way to get my 2.1 device to allow the user to select both types of content within a single Intent?
Putting the request into a function and then calling the function with onClick().
public void openGalleryImage(){
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Image "),
SELECT_IMAGE);
}
public void openGalleryVideo(){
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select vVideo "),
SELECT_VIDEO);
}

Categories

Resources