当前位置: 代码迷 >> Android >> 谷歌文件是mime类型
  详细解决方案

谷歌文件是mime类型

热度:116   发布时间:2023-08-04 12:42:13.0

我正在尝试使用Intent.ACTION_GET_CONTENT访问Android 4.4上的Google文档,但Google驱动器选择器中的文档显示为灰色(不可选)。 我可以很好地访问Google云端硬盘上的doc / docx文件,但不能访问Google文档。 我指定的mime类型与列出的类型相匹配。

这是代码片段(在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云端硬盘支持多种文件类型,“Google Doc”只是一种此类文件类型。 我怀疑您的Google云端硬盘可能包含其他文件类型。 例如,根据您的使用案例,您应该考虑包含以下MIME类型:

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

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

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

  相关解决方案