Using Intent.ACTION_PICK for specific path - android

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..

Related

Android Marshmallow 6.0, opening gallery via intent says No apps to perform the action

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

Handling URI tasks manually

I need to select an image from SD card in my android application.
I'm using URI to run device apps by below code:
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
I want to know if it is wise to handle URI tasks like above task by myself in my app or could it cause any trouble something like this.
Yes its fine and risk free. Incase you are trying to get images from Local storage, this is a good library :
https://github.com/jaydeepw/poly-picker

Intent to pick images, but not videos

In my Android app, I use the following code to launch an image picker:
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/jpg");
startActivityForResult(intent, INTENT_PICK_IMAGE);
But unfortunately, the system gallery activity that is called by this also display videos. Is there a way to prevent this?
I use this to only allow image types:
intent.setType("image/*");
Edit: setType() is based on MIME type, not file extension (See here: http://developer.android.com/reference/android/content/Intent.html#setType(java.lang.String))

How to limit the picture size took from IMAGE_CAPTURE intent

I use
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(getSomePath()+"temp.jpg")));
//intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, 0);
to get a picture and the saved picture returns as full-size.
But I want to get a limited picture, like 800*640, because on different devices I get different sizes, and I don't need that big picture.
I notice that there is a EXTRA_SIZE_LIMIT in MediaStore , but I can't find how to use it, what parameter should be set?
Answering my own question.
Finally I found that's because different manufacturers customize their Rom, including the Camera app, so the best way is not to call the default camera app, instead we can write a activity use hardware.camera to take picture. There are a lot of examples for this around the Internet too.
Unfortunately EXTRA_SIZE_LIMIT used for video limit in bytes.

modified android ACTION_VIEW intent

I execute the following code:
Uri uri =
Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
imageIdStr); Intent intent = new
Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setData(uri);
activity.startActivity(intent);
which opens the image viewer activity but I don't want to see the navigation arrows as well as the items in the menu. I only want the zoom controls. Is it possible to have it like that ?
That depends on the application that's actually displaying the image. On Android 2.0 and older, it's probably the Gallery app. On many Android 2.1+ apps, it's probably CoolIris' gallery. If the user has one of the many gallery apps from the market installed, it's up to those apps. I highly doubt there's a standardized extra to control that.
If you're really concerned about what the image display looks like, then you should handle that yourself. If you're really just trying to display an image (and maybe add pinch-zoom support?), it's a reasonable scope.

Categories

Resources