如何在Android L上选择图像或视频?

Moh*_*hit 3 android android-5.0-lollipop

我正在使用下面的代码,并且它在下面运行良好android 5。我可以从 SD 卡中选择图像或视频。

Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("video/* image/*");
getActivity().startActivityForResult(photoPickerIntent, 1);
Run Code Online (Sandbox Code Playgroud)

然而Android L它只显示视频。尝试搜索但没有找到任何内容,任何帮助将不胜感激。

Har*_*tar 5

嗨@Mohit,您可以使用此解决方案来处理图像和视频

Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("*/*");
getActivity().startActivityForResult(photoPickerIntent, 1);
Run Code Online (Sandbox Code Playgroud)

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

这里ACTION_GET_CONTENT只提供图库选择,而ACTION_PICK提供更多选项来从不同的操作中选择图像和视频,因此根据 @DipeshDhakal 答案,您应该只使用ACTION_GET_CONTENT

这也适用于 android L 和 api 10。