首页 > 解决方案 > 浏览具有特定扩展名的文件

问题描述

我正在开发一个显示 .dxf 文件的应用程序(使用 Kabeja 库)。我已经完成了所有部分,并且一切都按照我的意愿进行。问题是,我需要一个打开文件浏览器的按钮,以便用户可以从 sd 卡或本地存储导入他自己的 .dxf。它需要过滤文件以仅显示 .dxf,因此无法导入其他扩展名。我完全不知道如何做到这一点,也不知道如何制作一个基本的文件浏览器。你能帮我走上正轨吗?

谢谢

标签: javaandroidfile

解决方案


尝试这个

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);
 }

推荐阅读