如何通过意图仅选择doc,docx文件? [英] How to choose only doc,docx files through intent?
本文介绍了如何通过意图仅选择doc,docx文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Intent打开文件管理器,我需要知道如何仅显示.doc,.docx文件供用户选择.如何将setType设置为意图? 以下功能用于从文件管理器中选择文件.
I'm using Intent to open file manager, I need to know how to show only .doc, .docx files to choose by users. How to put setType to intent?` The Following function is used to choose file from file manager.
private void showFileChooser() {
Intent intent = new Intent();
//sets the select file to all types of files
intent.setType("application/*");
//allows to select data and return it
intent.setAction(Intent.ACTION_GET_CONTENT);
//starts new activity to select file and return data
startActivityForResult(Intent.createChooser(intent, "Choose File to Upload.."), PICK_FILE_REQUEST);
}`
推荐答案
您可以添加多种mime类型,例如:
You can add multiple mime types like this:
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
String[] mimetypes = {"application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/msword"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivityForResult(intent, REQUEST_CODE_OPEN);
以下mime类型对应于.docx
和.doc
文件
Following mime types corespond to .docx
and .doc
files
String[] mimetypes = {"application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/msword"};
这篇关于如何通过意图仅选择doc,docx文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文