android - Google 文档 mime 类型

标签 android

我正在尝试使用 Intent.ACTION_GET_CONTENTAndroid 4.4 上访问 Google 文档,但 Google 驱动器选择器中的文档显示为灰色(不可选择) .我可以很好地访问 Google 驱动器上的 doc/docx 文件,但不能访问 Google 文档。我指定的 MIME 类型与 Google Drive's Supported MIME Types 中列出的相匹配.

这是代码 fragment (在 Android 4.4 上运行):

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[]{
        "application/msword",
        "application/vnd.oasis.opendocument.text",
        "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
        "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
        "application/vnd.google-apps.document",
        "application/vnd.google-apps.kix",
});
startActivityForResult(intent, 0);

有什么地方可能是错的吗?

最佳答案

Google Drive 支持多种文件类型,“Google Doc”只是其中一种文件类型。我怀疑您的 Google Drive 可能包含其他文件类型。例如,根据您的用例,您应该考虑包括以下 MIME 类型:

application/vnd.google-apps.presentation
application/vnd.google-apps.spreadsheet
application/vnd.google-apps.drawing

但是,这不会涵盖所有可能的文件类型。您需要了解您想要支持的文件类型并包括它们的所有 MIME 类型。

或者,如果您想支持所有 可打开的文件类型,您根本不应该指定 EXTRA_MIME_TYPES。

关于android - Google 文档 mime 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22308601/

相关文章:

显示应用程序名称的 Android Studio 导航栏丢失了吗?

android - 获取当前工作日和日期

android - 计算应用程序正常运行时间 - android

ANDROID SQL 问题

android - 为什么我的应用程序与 Google Play 中的 nexus 7 不兼容?

java - 登录功能中出现意外的 token 错误

android - Android 上的 Ionic Cordova 相机插件错误

android - 如何在 Flutter 中创建这个布局?

android - 如何实现垂直移动的tabbs面板?

android - 将 SQL 查询分解为多个部分以访问内容提供者