【问题标题】:Open file dialog with extension filter for a custom extension with kotlin打开带有扩展过滤器的文件对话框,用于使用 kotlin 进行自定义扩展
【发布时间】:2019-09-12 21:44:32
【问题描述】:

有没有办法为此意图设置文件扩展名过滤器: 我想过滤扩展名为“.xxx”的文件

val intent = Intent()
                .setType("*/*") // <- it doesn't work if I put it here (".xxx")
                .setAction(Intent.ACTION_GET_CONTENT)
            startActivityForResult(Intent.createChooser(intent, "Select a file (.xxx)"), OPEN_FILE_CODE)

谢谢!

【问题讨论】:

  • 感谢您的回答!我正在寻找比交互所有文件列表更好的东西,然后选择那些具有我希望的扩展名的文件......没有任何方法可以添加像 .setExtensionFilter(".xxx") 这样的过滤器吗?再次感谢。

标签: android kotlin filter openfiledialog


【解决方案1】:

有没有办法为此意图设置文件扩展名过滤器

不,抱歉。

it doesn't work if I put it here (".xxx")

这是因为setType() 采用 MIME 类型,而不是文件扩展名。如果您的文件扩展名很常见并且映射到一个众所周知的 MIME 类型,您可以尝试将该 MIME 类型与setType() 一起使用。

【讨论】:

  • 感谢您的回答!我需要的扩展名是.shp。所以,它的知名度并不高。我想我会“手动”做这个过滤器。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-09
  • 2014-04-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多