我正在尝试使用 Intent.ACTION_GET_CONTENT
在 Android 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/