Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Gallery intent仅显示图像或视频,而不是同时显示两者?_Android_Android Intent_Android Camera_Android Camera Intent - Fatal编程技术网

Android Gallery intent仅显示图像或视频,而不是同时显示两者?

Android Gallery intent仅显示图像或视频,而不是同时显示两者?,android,android-intent,android-camera,android-camera-intent,Android,Android Intent,Android Camera,Android Camera Intent,我正在尝试允许用户从其设备中选择图像或视频,但目前它仅显示视频或图像,具体取决于以下代码中首先写入的内容: Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); //set type to include video too galleryInten

我正在尝试允许用户从其设备中选择图像或视频,但目前它仅显示视频或图像,具体取决于以下代码中首先写入的内容:

 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);
            }
        };
不确定我做错了什么,但setType似乎是对的,我尝试了在图像和视频之间使用逗号和不使用逗号

 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;

请尝试上面的内容。您需要有单独的选项

我遇到了同样的问题,它只使用列表中的第一个MIME类型

这最终对我起了作用:

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);
这对我很有用:

Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(gallery, PICK_MEDIA);

@找到解决办法了吗?