How to pick multiple files from Android's gallery? - android

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);

Related

Android pick limited number of images from gallery

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.

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

Android : Why Intent.EXTRA_LOCAL_ONLY shows Google Photos

What I'm trying to do in my application is to let the user choose a picture from his phone's gallery(Don't want to get gallery images only but also allowing a user to choose their app of choice). The code I'm using is as follows:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 1);
As per Intent.EXTRA_LOCAL_ONLY doesnt work
EXTRA_LOCAL_ONLY only tells the receiving app that it should return
only data that is present.
After adding intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); in above code,it hide google drive app and picasa app but still shows google photos(those photos are not in my device.)
Also I tried Android image picker for local files only but It hide all the apps having remote images excluding google photos.
Note : All the image paths are correct as I did Android Gallery on KitKat returns different Uri for Intent.ACTION_GET_CONTENT (thanks to #Paul Burke) but I don't want to pick internet/remote images.
So my question Is there any way to hide google photos app while pick an image from local device only. or Is google photos is part of Intent.EXTRA_LOCAL_ONLY
EXTRA_LOCAL_ONLY only tells the receiving app that it should return
only data that is present.
Google+ Photos stores both local and remote pictures and because of that is registered for that intent with that extra. However apparently it ignores wherever calling intent has EXTRA_LOCAL_ONLY set to true.
You could try removing G+ Photos from list manually (however this seems a bit hacky):
List<Intent> targets = new ArrayList<Intent>();
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
List<ResolveInfo> candidates = getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo candidate : candidates) {
String packageName = candidate.activityInfo.packageName;
if (!packageName.equals("com.google.android.apps.photos") && !packageName.equals("com.google.android.apps.plus") && !packageName.equals("com.android.documentsui")) {
Intent iWantThis = new Intent();
iWantThis.setType("image/*");
iWantThis.setAction(Intent.ACTION_GET_CONTENT);
iWantThis.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
iWantThis.setPackage(packageName);
targets.add(iWantThis);
}
}
Intent chooser = Intent.createChooser(targets.remove(0), "Select Picture");
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, targets.toArray(new Parcelable[targets.size()]));
startActivityForResult(chooser, 1);
Few words of explanation: targets.remove(0) will remove and return first Intent from targets list, so the chooser will consist only of one application. Then with Intent.EXTRA_INITIAL_INTENTS we add the rest.
The code snippet is modified version from this link.
Please remember to check all conditions like if there is at least one app available and so on.

Pick Image From Android Device's Gallery App

In my android application, I implemented a feature to pick an image from Gallery. For that earlier I was doing this-
Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT);
pickImageIntent.setType("image/*");
startActivityForResult(pickImageIntent, GALLERY_REQUEST_CODE);
By doing this, a dialog with all available image source application like Dropbox including Native Gallery app were displayed and it asks to choose one. Then I changed to
Intent pickImageIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickImageIntent.setType("image/*");
startActivityForResult(pickImageIntent, GALLERY_REQUEST_CODE);
By doing this most of applications were not diplayed but still some like Picasa are diplayed. I want to pick an image from Device's native gallery app only or we can say from either device's internal or external memory not from any third party application.
If any one has solution for this please help me with that.
To pick image from Gallery only
Intent pickImageIntent = new Intent(Intent.ACTION_PICK);
pickImageIntent.setType("image/*");
startActivityForResult(pickImageIntent, GALLERY_REQUEST_CODE);

How to get image path Uri and Crop for all devices

I have my main project which gets images from certain sources (returns Uri). The next step was to crop the image to scale (touch input). I recently found out that some phone manufacturer mess around with the android base classes so:
com.android.camera.action.crop
doesn't always exist.
So I've found a library that does cropping: https://github.com/lvillani/android-cropimage
I've added the library into my eclipse build path and project library's.
my question is, can I open the library like so:
Intent intent = new Intent("com.android.camera.action.CROP");
//intent.setClassName("com.android.camera", "com.android.camera.CropImage");
intent.setDataAndType(uri, "image/*");
intent.putExtra("crop", "true");
intent.putExtra("output", Uri);
intent.putExtra("outputFormat", "JPEG");
startActivityForResult(intent, 1);
And then retrieve the cropped image or do I have to do something else extra?
Another question: Also will this effect my app when I put it onto market (will the user need to download or accept permission for the extra library?
I want to make sure that my app works on everything, so is this the best way of doing it? Or is there better methods, please explain. (Also keep it simple, fairly new to Android dev!, thanks!)
I installed the library and made sure it was linking to my project and was in the build path, then I simply did:
Open file manager:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), PICK_FROM_FILE);
Alternatively if you want to capture from camera
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra("return-data", true);
startActivityForResult(intent, GET_IMAGE_FROM_CAMERA);
Then crop image:
Intent intent = new Intent(this, com.android.camera.CropImage.class);
intent.setData(uri);
intent.putExtra("return-data", true);
startActivityForResult(intent, CROP);
I've tested this on a few devices and it's working fine and dandy. Also works with camera.

Categories

Resources