【发布时间】:2017-04-04 10:01:34
【问题描述】:
在我的 android 应用程序中,我需要一个只选择图像和文档的文件选择器。我已经实现了它,但它会选择其他文件,如视频。我只需要选择 pdf、excel、txt 等文件和图像以及所有小于 5mb 的文件。下面是我目前使用的代码。
final String[] ACCEPT_MIME_TYPES = {"application/*", "image/*", "text/*" };
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_MIME_TYPES, ACCEPT_MIME_TYPES);
//intent.setType("file/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"),FILE_SELECT_CODE);
} catch (Exception ex) {
System.out.println("browseClick :"+ex);//android.content.ActivityNotFoundException ex
}
我没有做错什么让选择器选择视频和其他文件。请帮我解决这个问题。
【问题讨论】:
-
intent.setType("*/*");
标签: android android-intent filechooser filepicker