Reputation: 443
In my application i need to send images and videos from gallery to server, i had used following code for picking images and videos from galery. It works fine in the devices which are not in lollipop version.
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/* video/*");
startActivityForResult(photoPickerIntent,REQUEST_CODE_GALLERY_FILES);
And in the onActivityresult,
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent returnedIntent) {
super.onActivityResult(requestCode, resultCode, returnedIntent);
if (returnedIntent == null) return;
switch (requestCode) {
case REQUEST_CODE_GALLERY_FILES:
Uri uri = returnedIntent.getData();
break;
}
}
But in Nexus 5 like devices it shows only images, videos are not showed in the list. As there is Gallery is not available in Lollipop. How can i get video file also form gallery or from anywhere for lollipop devices.
Upvotes: 1
Views: 3969
Reputation: 1110
Add intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] {"image/*", "video/*"});
to the SDK20+ launching, along with main type.
Upvotes: 3
Reputation: 12861
Try this method.
private void pickImageOrVideo() {
if (Build.VERSION.SDK_INT < 19) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/* video/*");
startActivityForResult(photoPickerIntent,REQUEST_CODE_GALLERY_FILES);
} else {
Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("*/*");
startActivityForResult(photoPickerIntent, REQUEST_CODE_GALLERY_FILES);
}
}
for both image and video you can use setType(*/*);
if device is running on lollipop.
here ACTION_GET_CONTENT
is give only gallery selection while ACTION_PICK
give many more options to pick image and video from different action,
I hope it helps!
Upvotes: 4