android - 打开带有扩展过滤器的文件对话框,用于使用 kotlin 进行自定义扩展
问题描述
有没有办法为此意图设置文件扩展名过滤器:我想过滤带有此扩展名“.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)
谢谢!
解决方案
有没有办法为此意图设置文件扩展名过滤器
不,对不起。
it doesn't work if I put it here (".xxx")
那是因为setType()
采用 MIME 类型,而不是文件扩展名。如果您的文件扩展名是常见的并且映射到众所周知的 MIME 类型,您可以尝试将该 MIME 类型与setType()
.
推荐阅读
- php - 条件 SQL 查询 [VueJS]
- java - Android 软键盘adjustPan 进一步向上调整视图
- php - 表单动作不做任何事情
- google-apps-script - 只发送第一张纸
- javascript - Javascript 表单 onclick
- java - 使用来自唯一类的方法的 Java 程序运行不正常
- facebook - 允许其他人将他们的 Facebook 页面连接到我们的应用程序
- android - 由于 Json 元素为空字符串 ("") 而不是对象,Android 应用程序崩溃
- python-3.x - 熊猫:GroupBy Shift 和累积和
- c# - Console.Writeline 仅在使用异步等待时某些时候写入控制台