Gallery intent shows only image or video not both? - android

I am trying to allow a user to choose an image or video from his device, and currently it only shows video or image depending what is written first in the following code:
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
//set type to include video too
galleryIntent.setType("image/*, video/*");
startActivityForResult(galleryIntent, GALLERY_IMAGE_REQUEST_CODE);
}
};
not sure what I am doing wrong, but setType seems right I tried with and without the comma in between image and video...

case 2: //Choose Pic
Intent choosePhotoIntent = new Intent(Intent.ACTION_GET_CONTENT);
choosePhotoIntent.setType("image/*");
startActivityForResult(choosePhotoIntent, PICK_PHOTO_REQUEST);
break;
case 3: //Choose Video
Intent chooseVideoIntent = new Intent(Intent.ACTION_GET_CONTENT);
chooseVideoIntent.setType("video/*");
Toast.makeText(MyActivity.this,getString(R.string.video_message), Toast.LENGTH_LONG).show();
startActivityForResult(chooseVideoIntent, PICK_VIDEO_REQUEST);
break;
Try above..you need to have separate options..

I ran into the same issue where it would only use the first MIME type in the list.
This ended up working for me:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("*/*");
String[] mimeTypes = {"image/*", "video/*"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
startActivityForResult(intent, REQUEST_CODE_CAMERA_ROLL);

This works for me:
Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(gallery, PICK_MEDIA);

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

Android Intent for Capturing both Images and Videos?

Is there an Intent for starting a camera with options to capture both Pictures and Videos on Android?
I've used both MediaStore.ACTION_VIDEO_CAPTURE and MediaStore.ACTION_IMAGE_CAPTURE to capture either audio or video, but I can't find an Intent that will get the option for switching between both of them, as in this example app:
Thanks!
It is not possible to capture both image and video using the same intent, Your options are
1) Create your own camera this repo can be a good start But it is going to be a too much effort.
2) Use the Chooser Intent and pass the intent for both image and video, this will give you the option to choose between application which record video and camera separately. In this you cannot do both the things at same time but can choose application according to what you want to do, capture an image or record a video. Below is the code that works for me.
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
Intent chooserIntent = Intent.createChooser(takePictureIntent, "Capture Image or Video");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{takeVideoIntent});
startActivityForResult(chooserIntent, CAPTURE_MEDIA_RESULT_CODE);
I achieved it :)
You can do it by following --
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
contentSelectionIntent.setType("*/*");
intentArray = new Intent[]{takePictureIntent,takeVideoIntent};
chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Choose an action");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
startActivityForResult(chooserIntent, 1);
Similar example here
Happy coding :)
I could capture both image and video by using the below code.
Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);

android- open gallery and choose image and video

In my project I want to open a gallery on a button click and should be able to pick image or video to get path of them.
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
From above code i am able to open gallery but in this case i am only able to choose image. So, please help me in choosing video also.
Thanks in advance.
On Android 6.0 and above using "video/* image/" or "image/ video/*" type doesn't work, it only recognizes the first filter you specify. I solved the problem using this code:
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("*/*");
photoPickerIntent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] {"image/*", "video/*"});
startActivityForResult(photoPickerIntent, Constants.SELECT_PHOTO);
Although this will ask the user which app they want to use to select the image/video.
You can use the next snippet:
Intent mediaChooser = new Intent(Intent.ACTION_GET_CONTENT);
//comma-separated MIME types
mediaChooser.setType("video/*, image/*");
startActivityForResult(mediaChooser, RESULT_LOAD_IMAGE);
But I think that it only work on ICS or bigger
You need use the following as picking Intent
Intent photoLibraryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
photoLibraryIntent.setType("image/* video/*");
Below code solved my problem
final Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("*/*");
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
2022 Android 9
I've tried everything available online, and accidently mixed 2 solutions that turned out to work.
This only gives photo library and google photos as options, and you can select photos AND videos.
libraryIntent.setType("video/*, image/*");
String[] mimetypes = {"image/*", "video/*"};
libraryIntent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
Not enough rep to comment, but #YYamil's response works well.
Intent mediaChooser = new Intent(Intent.ACTION_GET_CONTENT);
//comma-separated MIME types
mediaChooser.setType("video/*, image/*");
startActivityForResult(mediaChooser, RESULT_LOAD_IMAGE);
If you're using the new registerForResultActivity, create a copy of ActivityResultContracts.GetMultipleContents() and put in createIntent:
#CallSuper
override fun createIntent(context: Context, input: String): Intent {
return Intent(Intent.ACTION_GET_CONTENT)
.addCategory(Intent.CATEGORY_OPENABLE)
.setType(input)
.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
.putExtra(Intent.EXTRA_MIME_TYPES, arrayOf("image/*", "video/*")) // this does the trick
}
This is the best i known...... Try this for once....
final CharSequence[] options = {"Images", "Videos", "Cancel"};
AlertDialog.Builder builder = new AlertDialog.Builder(OpenGallery.this);
builder.setTitle("Select From...");
builder.setItems(options, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int item) {
if (options[item].equals("Images")) {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(intent, 1);
} else if (options[item].equals("Videos")) {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(intent, 1);
} else if (options[item].equals("Cancel")) {
dialog.dismiss();
}
dialog.dismiss();
}
});
builder.show();
Change your Intent to this:
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
When trying to get videos you need to state to mediaStore that video is in order and not images as you wrote.
Well android has put a lot of restriction on accessing the external content. I ended up using 3rd party library. This one is good.:
https://github.com/AnilFurkanOkcun/UWMediaPicker-Android
implementation 'com.github.AnilFurkanOkcun:UWMediaPicker-Android:1.3.0'
UwMediaPicker
.with(this) // Activity or Fragment
.setGalleryMode(UwMediaPicker.GalleryMode.ImageGallery) // GalleryMode: ImageGallery/VideoGallery/ImageAndVideoGallery, default is ImageGallery
.setGridColumnCount(4) // Grid column count, default is 3
.setMaxSelectableMediaCount(10) // Maximum selectable media count, default is null which means infinite
.setLightStatusBar(true) // Is llight status bar enable, default is true
.enableImageCompression(true) // Is image compression enable, default is false
.setCompressionMaxWidth(1280F) // Compressed image's max width px, default is 1280
.setCompressionMaxHeight(720F) // Compressed image's max height px, default is 720
.setCompressFormat(Bitmap.CompressFormat.JPEG) // Compressed image's format, default is JPEG
.setCompressionQuality(85) // Image compression quality, default is 85
.setCompressedFileDestinationPath(destinationPath) // Compressed image file's destination path, default is "${application.getExternalFilesDir(null).path}/Pictures"
.launch{selectedMediaList-> } // (::onMediaSelected) // Will be called when media is selected

call android gallery for both image and video

when i have to get some image or video
i did like this
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("video/*");
startActivityForResult(intent , ActNetwork.EXTRA_FLAG_SEARCH_LOCAL_VOD);
and
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent , ActNetwork.EXTRA_FLAG_SEARCH_LOCAL_VOD);
i try to
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/* , video/*");
but in occured error
how can i solve that problem..
thanks your reply
Try this
final Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/* video/*");
startActivityForResult(galleryIntent, REQUEST_CODE);
have you tried with
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("media/*");
startActivityForResult(intent , ActNetwork.EXTRA_FLAG_SEARCH_LOCAL_VOD);
Try this
intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 1);
Works on 2.1
I was also having the same issue and I found the solution.
Intent pickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
pickerIntent.setType("image/*, video/*");
pickerIntent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] {"image/*", "video/*"});
startActivityForResult(pickerIntent, REQUEST_CODE_FOR_MEDIA);
The key here is pickerIntent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] {"image/*", "video/*"});
Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("*/*");
photoPickerIntent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] { "video/* images/*"});
startActivityForResult(photoPickerIntent, REQUEST_GALLERY);

Categories

Resources