java - 浏览具有特定扩展名的文件
问题描述
我正在开发一个显示 .dxf 文件的应用程序(使用 Kabeja 库)。我已经完成了所有部分,并且一切都按照我的意愿进行。问题是,我需要一个打开文件浏览器的按钮,以便用户可以从 sd 卡或本地存储导入他自己的 .dxf。它需要过滤文件以仅显示 .dxf,因此无法导入其他扩展名。我完全不知道如何做到这一点,也不知道如何制作一个基本的文件浏览器。你能帮我走上正轨吗?
谢谢
解决方案
尝试这个
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
// Verify that the intent will resolve to an activity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, 1);
}
如果您想强制执行应用选择器
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
Intent chooser = Intent.createChooser(sendIntent, "Title");
// Verify that the intent will resolve to an activity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(chooser, 1);
}
推荐阅读
- python - 如何使用 Hasura GraphQL 查询 postgres RangeField
- javascript - 以 ANGULAR 搜索时出现在单个页面上的搜索结果
- javascript - 我怎样才能使用超过 2 个部分的这个 JavaScript 代码?
- angular - Ionic 4 的 NGRX 多订阅问题
- java - 由于 ClassNotFoundException,Spring Boot 2 DataJpaTest 无法自省带注释的方法
- ruby-on-rails - Elasticsearch 没有得到 searchkick 的许可
- python - struct.pack 和 struct.unpack 只做字符串的第一个字符
- ios - Xcode 11.4 Objective-C 语言的快速帮助,而不是 swift 语言,用于带有 Cocoapods 的 firebase API(iOS 13.4 应用程序)
- javascript - 它给定的未定义。无法从 Firebase 中检索名称
- django - Django - URL 配置