gpt4 book ai didi

android - 从 Google 照片提供商选择视频不会提供 mimetype 信息

转载 作者:行者123 更新时间:2023-12-03 14:38:27 27 4
gpt4 key购买 nike

我创建了一个示例 here重现此问题。
我在一个 API 级别为 29 的模拟器上运行这个项目,并从谷歌照片提供商那里选择一个视频。
但我无法弄清楚如何获取所选文件的 mimeType。
我使用了 ContentResolver 的 getType 方法,它返回 null 和 ContentResolver 查询方法,它以某种方式向我抛出 IllegalArgumentException。我已经附上了相同的屏幕截图。
enter image description here

注意:如果我通过浏览目录选择相同的文件,一切正常,但是当我使用谷歌照片提供程序时,它会失败。

这是我的代码::

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 + "");
}
}
}

这就是我开始 Intent 的方式::
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("video/*");
startActivityForResult(i, IMAGE_VIDEO_FETCH);

任何人都可以用正确的方法帮助我找出所选文件的 mimetype 吗?
PS:我试过 ContentResolver.getType、MimeTypeMap 和 ContentResolver.query。它们都不起作用。

最佳答案

我浪费了几天时间试图找出问题所在。不幸的是,它原来是谷歌照片 4.17 版中的一个错误,似乎已在 4.32 版中修复

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

关于android - 从 Google 照片提供商选择视频不会提供 mimetype 信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60182338/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com