Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.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 从多媒体资料中选择图像、视频或音频文件_Android_Android Intent - Fatal编程技术网

Android 从多媒体资料中选择图像、视频或音频文件

Android 从多媒体资料中选择图像、视频或音频文件,android,android-intent,Android,Android Intent,我已经开发了Android应用程序。我需要从图库中选择图像、音频或视频。我使用了intent.setType(“image/,video/,audio/*”);。但没有解决办法。它只接受图像。没有视频或音频 Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

我已经开发了Android应用程序。我需要从图库中选择图像、音频或视频。我使用了intent.setType(“image/,video/,audio/*”);。但没有解决办法。它只接受图像。没有视频或音频

 Intent galleryIntent = new Intent(Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                galleryIntent.setType("image/*,audio/*,video/*");
                startActivityForResult(galleryIntent, 0);


谢谢你的回复。我打开上面的链接,但我不明白。你能解释一下吗!!!!如果您不理解该答案的部分内容,则需要详细解释您不理解的内容。我保留了如下代码:GalleryContent.setType(“应用程序/图像|应用程序/音频|应用程序/视频”);但是它崩溃了。的第一个词是:“
setType()
不接受管道分隔的类型列表”(强调添加)。感谢您的回复。我打开上面的链接,但我不明白。你能解释一下吗!!!!如果您不理解该答案的部分内容,则需要详细解释您不理解的内容。我保留了如下代码:GalleryContent.setType(“应用程序/图像|应用程序/音频|应用程序/视频”);但是它崩溃了。的第一个词是:“
setType()
不采用管道分隔的类型列表”(强调添加)。
        btn_browser_id.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent galleryIntent = new Intent(Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                galleryIntent.setType("image/*,audio/*,video/*");
                startActivityForResult(galleryIntent, 0);
            }
        });


         @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        try {
            // When an Image is picked
            if (requestCode == 0 && resultCode == RESULT_OK && null != data) {

                Uri selectedMediaUri = data.getData();

                if (selectedMediaUri.toString().contains("image")) {
                   // Log.d(logmessage,"Entered into the image************************* "+selectedMediaUri);
                    //handle image
                    String[] filePathColumn = {MediaStore.Images.Media.DATA};
                    file_type="Image";
                    Cursor cursor = getContentResolver().query(selectedMediaUri, filePathColumn, null, null, null);
                    assert cursor != null;
                    cursor.moveToFirst();

                    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                    mediaPath = cursor.getString(columnIndex);
                    uploadfile.setText(mediaPath);
                    fileupload(mediaPath);
                    //imgView.setImageBitmap(BitmapFactory.decodeFile(mediaPath));
                    cursor.close();


                } else  if (selectedMediaUri.toString().contains("video")) {
                    //handle video
                    Log.d(logmessage,"Entered into the Video************************* "+selectedMediaUri);
                    file_type="Video";
                    String[] filePathColumn = {MediaStore.Video.Media.DATA};

                    Cursor cursor = getContentResolver().query(selectedMediaUri, filePathColumn, null, null, null);
                    assert cursor != null;
                    cursor.moveToFirst();

                    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);

                    mediaPath = cursor.getString(columnIndex);
                    uploadfile.setText(mediaPath);
                    fileupload(mediaPath);
                    // Set the Video Thumb in ImageView Previewing the Media
                    //imgView.setImageBitmap(getThumbnailPathForLocalFile(MainActivity.this, selectedMediaUri));
                    cursor.close();

                } else  if (selectedMediaUri.toString().contains("audio")) {
                    //handle video
                    Log.d(logmessage,"Entered into the Video************************* "+selectedMediaUri);
                    file_type="Audio";
                    String[] filePathColumn = {MediaStore.Audio.Media.DATA};

                    Cursor cursor = getContentResolver().query(selectedMediaUri, filePathColumn, null, null, null);
                    assert cursor != null;
                    cursor.moveToFirst();

                    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);

                    mediaPath = cursor.getString(columnIndex);
                    uploadfile.setText(mediaPath);
                    fileupload(mediaPath);
                    // Set the Video Thumb in ImageView Previewing the Media
                    //imgView.setImageBitmap(getThumbnailPathForLocalFile(MainActivity.this, selectedMediaUri));
                    cursor.close();

                }


            }  else {
                Toast.makeText(this, "You haven't picked Image/Video", Toast.LENGTH_LONG).show();
            }
        } catch (Exception e) {
            Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG).show();
        }

    }