Intent to pick images, but not videos - android

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

Related

How to use an Image Uri outside Activity?

I'm creating a Sign-Up page from my app that has the option to obtain an image from the gallery using this code:
Intent pickImageFileIntent = new Intent(Intent.ACTION_PICK);
pickImageFileIntent.setType("image/*");
String pickTitle = getString(R.string.select_img_gallery);
Intent chooserIntent = Intent.createChooser(pickImageFileIntent, pickTitle);
startActivityForResult(chooserIntent, PICK_IMAGE);
After the user selects the image from the gallery I show that image in an ImageView using Glide, and it works fine. But when I try to use that image's Uri in another activity I get permission denied and the app crashes, so I think the Uri only has permissions for the Activity where ti was obtained. I tried to use ACTION_GET_DOCUMENT instead of ACTION_PICK and it works but the problems is in the Intent chooser it only shows the file explorer instead of the default media gallery and Google Photos, like when I use ACTION_PICK. Is there a way to use the Uri outside the activity while still using ACTION_PICK?

Set Image Wallpaper Intent in Flutter

Hi i have tried different ways to set my downloaded images from server as wallpaper using the native android intent in flutter but so far i am unable to implement it.
I have tried the intent package from pub.dev flutter but this code doesn't make my image pass through intent.
android_intent. Intent()
..setAction(android_action.Action.ATTACH_DATA)
..setData(outputFileUri)
//..putExtra(Extra.EXTRA_STREAM, outputFileUri)
..addFlag(1)
..setType('image/*')
..startActivity().catchError((e) => print(e));
Anyway to fix this would be really helpful. I am also sharing the functionality i want like in the image
t,
This should work for your situation:
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setDataAndType(uri, "image/*");
intent.putExtra("mimeType", "image/*");
this.startActivity(Intent.createChooser(intent, "Set as:"));
It's also independent of the image data type.

How to fetch images and videos together from external apps using intents android?

I wish to launch an intent which can allow me to choose images and videos together ath the same time. Currently I see that I can set type of intent as image or as video but not both together.
Intent intent = new Intent("android.intent.action.GET_CONTENT");
intent.addCategory("android.intent.category.OPENABLE");
intent.setType("image/*");
OR
intent.setType("video/*");
Please suggest
Thanks

Using Intent.ACTION_PICK for specific path

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

Android Intent Save Path

At the moment I am using two intents. One for voice-recording, another for the camera:
Intent photoIntent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(photoIntent, ACTIVITY_TAKE_PHOTO);
Intent voiceIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivityForResult(voiceIntent, ACTIVITY_RECORD_SOUND);
My aim is to put an Extra to each of those which contains the path where to store the picture / the recorded Voice. Is there an option to do so?
You can use the EXTRA_OUTPUT extra to specify a destination Uri for images taken with ACTION_IMAGE_CAPTURE (but not RECORD_SOUND_ACTION; for that, the returned bundle will contain the file path).
An example can be found here, excerpt below:
Loosely quoting yanokwa:
// fire off the intent
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
Uri.fromFile(new File("<temp file path here>")));
startActivityForResult(i, mRequestCode);
BTW, a similar question can be found here.
I am not sure but my first thought would be to set the data uri of the intent and see if that does anything.
AFAIK this is not possible from firing off Intents.
When the given activity returns the picture/voice data should be in the result. Take that data and then save it from within your activity to your desired location. The camera/recorder activity simply handles pictures/audio and then returns the result back to you to handle.

Categories

Resources