使用 kotlin 自定义扩展的带有扩展过滤器的打开文件对话框
Open file dialog with extension filter for a custom extension with 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)
谢谢!
Is there any way to set a file extension filter for this intent
不,抱歉。
it doesn't work if I put it here (".xxx")
这是因为 setType()
采用 MIME 类型,而不是文件扩展名。如果您的文件扩展名很常见并且映射到众所周知的 MIME 类型,您可以尝试使用该 MIME 类型 setType()
.
有没有办法为此意图设置文件扩展名过滤器: 我想过滤扩展名为“.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)
谢谢!
Is there any way to set a file extension filter for this intent
不,抱歉。
it doesn't work if I put it here (".xxx")
这是因为 setType()
采用 MIME 类型,而不是文件扩展名。如果您的文件扩展名很常见并且映射到众所周知的 MIME 类型,您可以尝试使用该 MIME 类型 setType()
.