从Google相册提供者中选择视频不会提供模仿类型信息 [英] Selecting video from Google Photos provider doesn't give mimetype information

查看:109
本文介绍了从Google相册提供者中选择视频不会提供模仿类型信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在此处创建了一个示例,以重现此问题. 我正在使用API​​级别29的模拟器上运行此项目,并从google照片提供程序中选择一个视频. 但是我不知道如何获取所选文件的mimeType. 我用过ContentResolver的getType方法,该方法返回null,还有ContentResolver查询方法,该查询方法以某种方式向我抛出了IllegalArgumentException.我已经附上了相同的屏幕截图.

I've created a sample here to reproduce this issue. I'm running this project on an emulator with API level 29 and selecting a video from google photos provider. But I cannot figure out how to get the mimeType of the selected file. I've used ContentResolver's getType method which returns null and also ContentResolver query method which somehow throws an IllegalArgumentException to me. I've attached a screenshot for the same.

注意:如果我通过浏览目录选择相同的文件,则一切正常,但是当我使用google photos provider时,它将失败.

Note: Everything works fine if I select the same file by navigating through the directories, but when I use the google photos provider, it fails.

这是我的代码::

protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        if (resultCode == RESULT_OK && requestCode == IMAGE_VIDEO_FETCH) {
            Uri selectedFileURI = intent.getData();
            String type = this.getContentResolver().getType(selectedFileURI);

            if (type == null || TextUtils.isEmpty(type)) {
                // This shouldn't happen right?
                // Since https://developer.android.com/training/secure-file-sharing/retrieve-info
                // mentions a FileProvider determines the file's MIME type from its filename extension. I've to add this block
                Cursor cursor = null;
                try {
                    cursor = getContentResolver().query(selectedFileURI, null, null, null, null);
                    if (cursor != null && cursor.moveToFirst()) {
                        int colIndex = cursor.getColumnIndex(MediaStore.MediaColumns._ID);
                        type = cursor.getString(colIndex);
                    }
                } catch (IllegalArgumentException e) {
                    Log.d("Check Type :: ", type + "");
                    e.printStackTrace();
                } finally {
                    if (cursor != null) {
                        cursor.close();
                    }
                }
            } else {
                Log.d("Type:: ", type + "");
            }
        }
    }

这就是我开始意图的方式:

And this is how I start an intent::

Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("video/*");
startActivityForResult(i, IMAGE_VIDEO_FETCH);

任何人都可以通过正确的方法找出所选文件的模仿类型吗? PS:我已经尝试过ContentResolver.getType,MimeTypeMap和ContentResolver.query.它们都不起作用.

Can anyone help me out with the correct way to figure out the mimetype of the selected file? PS: I've tried ContentResolver.getType, MimeTypeMap and ContentResolver.query. None of them works.

推荐答案

我浪费了几天的时间试图找出问题所在.不幸的是,事实证明这是Google照片4.17版中的一个错误,该错误似乎在4.32版中已修复

I wasted couple of days trying to figure out where the problem exists. Unfortunately it turned out to be a bug in google photos version 4.17 which seems to be fixed in version 4.32

这是链接的Google问题 https://issuetracker.google.com/issues/149416521

Here is the linked google issue https://issuetracker.google.com/issues/149416521

这篇关于从Google相册提供者中选择视频不会提供模仿类型信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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