问题描述
我正在尝试使用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);
关于可能出错的任何想法?
1楼
Google云端硬盘支持多种文件类型,“Google Doc”只是一种此类文件类型。 我怀疑您的Google云端硬盘可能包含其他文件类型。 例如,根据您的使用案例,您应该考虑包含以下MIME类型:
application/vnd.google-apps.presentation
application/vnd.google-apps.spreadsheet
application/vnd.google-apps.drawing
但是,这不会涵盖所有可能的文件类型。 您需要了解要支持的文件类型,并包括所有MIME类型。
或者,如果要支持所有可打开的文件类型,则根本不应指定EXTRA_MIME_TYPES。