Open gallery except .gif images - android

I want to open device gallery except .gif images.
I tried the following code but it showing all images in gallery, let me help
Intent pickPhoto = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
if(Build.VERSION.SDK_INT >21){
pickPhoto.setType("image/*");
pickPhoto.setAction(Intent.ACTION_GET_CONTENT);
}
startActivityForResult(pickPhoto, PICK_FROM_GALLERY);

To open the device gallery except for .gif images, you need to set the supported mimeTypes for the gallery intent i.e., image types you need to pick from the gallery like png, jpg, jpeg, etc.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
String[] mimeTypes = {"image/png", "image/jpg", "image/jpeg"};
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
startActivityForResult(intent, REQUEST_GALLERY);

Related

How to pick only videos from gallery?

I want to be able to pick only videos from gallery but I only found tutorials that select images but I only want to be able to select videos.
Can anyone help?
For example, when you use an intent, you can set the type of your intent. Here I'm using "video/*" to get all videos of my device.
Intent galleryIntent = new Intent(Intent.ACTION_PICK);
galleryIntent.setType("video/*");
startActivity(galleryIntent);
Try this code..
protected int REQUEST_TAKE_GALLERY_VIDEO = 3;
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Video"),REQUEST_TAKE_GALLERY_VIDEO);

Open image for sharing

I have Android Xamarin application with imageview
OnClik I lunch intent to preview image
File file = new File(photoPath);
Intent intent = new Intent(Intent.ActionView);
intent.SetDataAndType(Uri.FromFile(file), "image/*");
intent.SetFlags(ActivityFlags.NoHistory);
StartActivity(intent);
from apps I choose 'Gallery'
when the image is opend there are no sharing options
when I open image from device 'Gallery' has sharing options
Image is saved to SD card before preview.
what am I doing wrong ?
solution that worked for me
Intent intent = new Intent();
intent.PutExtra(Intent.ActionView, photoPath);
intent.SetType("image/*");
StartActivity(Intent.CreateChooser(intent, "Select Picture"));
now I get my image opend in gallery and I can use sharing options too
Do it using Intent.ACTION_SEND and you'll get that sharing option.
Also try with Intent.ACTION_GET_CONTENT.
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), 1);

How can I upload photos from Android's mobile gallery?

I want to upload photos from Android's mobile gallery from my app. How can I do that?
You should use the MediaStore to be able to get pictures from the gallery:
http://developer.android.com/reference/android/provider/MediaStore.Images.Media.html
Edit:You can get the image with this:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, 1);
And you get the bitmap with this in your onActivityResult :
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity()
.getContentResolver(), data.getData());

Android image picker for local files only

I'm using the built in Android image picker as follows:
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
m_activity.startActivityForResult(photoPickerIntent, PHOTO_PICKER_ID);
Is there any way to restrict this to show only locally available files. On my device it is currently picking up Picasa thumbnails and I'd like to exclude all images that are not actually present on the device.
Adding intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); will allow for local files only. It will exclude picasa images. Hope this helps.
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(Intent.createChooser(intent,
"Complete action using"), PHOTO_PICKER_ID);
User this code to launch intent to get local image chooser.
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Complete action using"), PHOTO_PICKER_ID);

Downloading images from the gallery in android

I am developing an app in which i need to import images from the default gallery to the storage in sd card that I use for the app. Is it possible?
You can use an Intent to have the user pick an image from the default gallery.
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
photoPickerIntent.setType("image/*");
Uri path = getTempUri("/mnt/sdcard/yourfolder");
photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT, path);
photoPickerIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
startActivityForResult(photoPickerIntent, filenameInt);
This will save the image picked by the user to the path you specified. There are some more options like cropping and scaling:
photoPickerIntent.putExtra("crop", "true")
.putExtra("aspectX", 4)
.putExtra("aspectY", 3)
.putExtra("outputX", 800)
.putExtra("outputY", 600)
.putExtra("scale", true);
I don't know if this is exactly what you're aiming for though.

Categories

Resources