please help
how can i do preselection all for user in a native android gallery ?
here is a code
Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
galleryIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
galleryIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, multiple);
galleryIntent.addCategory(Intent.CATEGORY_OPENABLE);
final Intent chooserIntent = Intent.createChooser(galleryIntent, "Pick an image");
activity.startActivityForResult(chooserIntent, IMAGE_PICKER_REQUEST);
its working fine, but initial stage 0 files are selected
thanks
There is no means of pre-selecting anything when using ACTION_GET_CONTENT, let alone pre-selecting everything.
Also note that ACTION_GET_CONTENT is not tied to a gallery app, and there is no single "native Android gallery" app across the ~10,000 Android device models.
Related
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
// intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
startActivityForResult(intent, CHOOSE_FILE_RESULT_CODE);
I am working on an application that helps the user to share his/her any accessible item(file) in the device. Codes above help user to select file(s) in the device. It is perfect! But I also want to give an opportunity to users as sharing their contacts(full contact details) with others by using my app. I tried intent.putExtras() but it supported in Build.VERSION.SDK_INT >= 19 devices (my app's min SDK is 17). It seems contact pick action requires different kind of intent type rather than "*/*". So, how merge these types of intents together? What can I do to solve the problem?
p.s I added following line to the manifest:
<uses-permission android:name="android.permission.READ_CONTACTS"/>
Brandon Zamudio marked the question as possible duplicate of this question but I can explain why it is not. In original question Hardik Trivedi wanted to pick contacts using intent. But in my case I want to give some different options to user to select. So, my problem should not be same with the original question. I did not share some pieces of my codes, but it is different one. Thanks for attention.
Actually, I wrote almost same codes approximately 2 years ago. In two days I searched for these lines. Fortunately I found them in my second Hello World! application. :)
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // for Camera app
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE); // not necessary, but recommended
Intent contacts = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
contacts.setType(ContactsContract.Contacts.CONTENT_TYPE);
Intent chooserIntent = createChooser(intent, "Select item");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{ takePicture, contacts });
startActivityForResult(chooserIntent, CHOOSE_FILE_RESULT_CODE);
I am trying to open gallery on Nexus 7 with Android 6.0. It does not have in built gallery, but it does have the Google Photos app.
I am using the following code to open the gallery :
Intent i = new intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Always show the chooser (if there are multiple options available)
startActivityForResult(Intent.createChooser(i, "Select Picture"), PICK_IMAGE_REQUEST);
The above code works well in all the versions below 6.0. And Please note that I am already using RUN TIME PERMISSIONS for accessing gallery and have given the permission to access gallery / or externa storage.
Now when the code is executed, I get a transparent screen with heading "Select Picture" and in the middle a text No Apps can perform this action.
Now what do I do to pick or choose image and use in my app.
Any help is appreciated.
Thanks
I am using the following code to open the gallery
That code has nothing to do with a "gallery". That code is requesting to pick a piece of content from a particular collection of content. There may be zero, one, or several activities on the device that offer to support that Intent structure.
The above code works well in all the versions below 6.0
Only on devices that happen to have one or more activities that satisfies that Intent structure.
Now what do I do to pick or choose image and use in my app.
Intent i = new intent(Intent.ACTION_GET_CONTENT).setType("image/*");
// use PackageManager to see if there is anything that supports this
// Intent structure, or just blindly make the following call and handle
// the ActivityNotFoundException
startActivityForResult(i, PICK_IMAGE_REQUEST);
I am using this code , so that only gallery opens and not any other option to pick image
There is nothing in your code that limits it to just a "gallery".
Not allowed to comment because I don't have enough points. But here's just a suggestion, how about if you just passed the intent directly? Like this:
startActivityForResult(i, PICK_IMAGE_REQUEST);
Use this line of code rather than what you have done
Intent i = new intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, PICK_IMAGE_REQUEST);
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.
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);
I am trying to use Android gallery to pick image. Launching gallery is easy for that purpose
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1);
However, I need to limit images that are shown in the gallery to specific path on device (i.e. to show images from single folder only). Is this possible to do and how?
Sorry, no this is not possible.
Also you are using this Intent protocol wrong. As per http://developer.android.com/reference/android/content/Intent.html#ACTION_PICK this protocol expects that you put the content: URI of the data set you want the picker to select from.
That said, you should consider ACTION_PICK deprecated. The modern action is ACTION_GET_CONTENT which is much better supported; you will find support of ACTION_PICK spotty and inconsistent. Unfortunately, ACTION_GET_CONTENT also does not let you specify a directory.
Why not ?
Intent galleryIntent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivity(galleryIntent)
Good luck with..