如何在Android L上选择图像或视频? [英] How to pick image or video on Android L?

查看:62
本文介绍了如何在Android L上选择图像或视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的代码,并且在android 5下可以正常工作.我可以从SD卡中选择图像或视频.

I am using below code and it works fine below android 5. I am able to pick image or video from SD card.

Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("video/* image/*");
getActivity().startActivityForResult(photoPickerIntent, 1);

但是在Android L上,它仅显示视频. 尝试搜索但没有找到任何东西,将不胜感激.

However on Android L it shows only videos. tried searching but didn't find anything, any help will be appreciated.

推荐答案

@ Mohit,您可以将此解决方案用于图像和视频

hi @Mohit you can use this solution for image and video

Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("*/*");
getActivity().startActivityForResult(photoPickerIntent, 1);

对于图像和视频,您都可以使用setType(*/*);

for both image and video you can use setType(*/*);

此处 ACTION_GET_CONTENT 仅提供图库选择,而 ACTION_PICK 提供更多选项以从不同操作中选择图像和视频,因此,根据@DipeshDhakal答案,您应仅使用 ACTION_GET_CONTENT .

here ACTION_GET_CONTENT is give only gallery selection while ACTION_PICK give many more options to pick image and video from different action, So as per @DipeshDhakal answer you should use only ACTION_GET_CONTENT.

这也适用于android L和api 10.

and this is work on android L and api 10 also.

这篇关于如何在Android L上选择图像或视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆