Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.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 无法从nexus 5棉花糖中的谷歌照片应用程序中拾取照片和视频_Android_Android Gallery - Fatal编程技术网

Android 无法从nexus 5棉花糖中的谷歌照片应用程序中拾取照片和视频

Android 无法从nexus 5棉花糖中的谷歌照片应用程序中拾取照片和视频,android,android-gallery,Android,Android Gallery,我在Nexus5的“谷歌照片”应用程序中同时获取照片和视频时遇到问题。在其他应用程序中,它工作正常,但问题仅限于谷歌照片。请帮助我,使我可以看到完整的画廊(不仅是图片或视频) 这是我的按钮的一次点击: @Click(R.id.ivGallery) void addMedia() { Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

我在Nexus5的“谷歌照片”应用程序中同时获取照片和视频时遇到问题。在其他应用程序中,它工作正常,但问题仅限于谷歌照片。请帮助我,使我可以看到完整的画廊(不仅是图片或视频)

这是我的按钮的一次点击:

@Click(R.id.ivGallery)
    void addMedia() {
        Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        intent.setType("*/*");
        intent.setType("image/jpeg");
        intent.setType("video/mp4");
        startActivityForResult(intent, GALLERY_REQUEST_CODE);
    }

我不知道为什么它对你不起作用,但如果照片没有保存在设备上,我在从谷歌照片获取照片时也遇到了类似的问题。 我所做的基本上是检查路径是否为空(意味着图像不在设备上),如果是,我只是装箱一个新文件,从流读取到缓冲区,并将其保存到新文件中。。为我工作

    public static String getImagePathForImageDownloadedFromGooglePhotos(Context context, Uri uri)
{
    ParcelFileDescriptor parcelFileDescriptor = null;
    try {
        parcelFileDescriptor = context.getContentResolver()
                .openFileDescriptor(uri, "r");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    if (parcelFileDescriptor == null)
        return null;

    FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
    InputStream inputStream = new FileInputStream(fileDescriptor);
    try {
        //noinspection SpellCheckingInspection
        File file = new File(context.getCacheDir(), new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()));
        String path = file.getAbsolutePath();
        try {
            try (OutputStream output = new FileOutputStream(file)) {
                byte[] buffer = new byte[4 * 1024];
                int read;

                while ((read = inputStream.read(buffer)) != -1) {
                    output.write(buffer, 0, read);
                }

                output.flush();
                return path;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } finally {
        try {
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return null;
}
}试试这个

@Click(R.id.ivGallery)
void addMedia() {
    // ACTION_PICK : is showing many option
    // ACTION_GET_CONTENT : only gallery
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

    // other setType calls aren't required. 
    intent.setType("*/*"); 

    startActivityForResult(intent, GALLERY_REQUEST_CODE);
}

对于图像和视频的组合,您需要放置setType()。 比如:


setType()适用于两种类型的媒体,您必须从多媒体资料中选择。

您可以使用此选项选择所有类型的文件

 Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
 intent.addCategory(Intent.CATEGORY_OPENABLE);
 intent.setType("*/*");
 startActivityForResult(intent, PICKFILE_REQUEST_CODE);

您是否添加了运行时权限?否@DheerubhaiBansal,但在从设备手动授予权限后,它不起作用:(选择图片后无法进入图像视图,但可以……您的答案是正确的,但它不适用于谷歌照片应用程序……此应用程序仅拍摄第一种MIME
 Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
 intent.addCategory(Intent.CATEGORY_OPENABLE);
 intent.setType("*/*");
 startActivityForResult(intent, PICKFILE_REQUEST_CODE);