我正在使用 ACTION_OPEN_DOCUMENT Intent 来启动系统文件选择器。用户应该选择一个“gpx”文件(blabla.gpx)。
我希望选择器只允许选择带有“.gpx”扩展名的文件。
MIME 类型为“application/gpx+xml”,但是当我在 Intent 的 settype() 中指定该类型时,gpx 文件不可选。
有没有办法创建“application/gpx”的自定义 mime 类型,仅供在我的应用程序中使用?如果是这样,如何将其与“,gpx”文件扩展名关联起来?
也许我可以更改与“application/gpx+xml”mimne 类型关联的文件扩展名?
或者,还有其他方法可以完成我想做的事情吗?
最佳答案
I am using a ACTION_OPEN_DOCUMENT intent to launch a system file picker.
ACTION_OPEN_DOCUMENT
不限于文件。
I would like to have the picker only allow files with a ".gpx" extension to be selected.
ACTION_OPEN_DOCUMENT
不限于使用文件扩展名的文档提供程序。和GPX-formatted content不限于扩展名为 .gpx
的文件。
There is a MIME type of "application/gpx+xml", but when I specify that in the intent's settype(), the gpx files are not selectable.
在 Android SDK 模拟器或 Google Pixel 设备上试用。如果您遇到同样的问题,请提交错误报告。
但是,请记住,MIME 类型和关联文件扩展名的列表可能由设备制造商自定义。这就是为什么我建议在 SDK 模拟器或 Google Pixel 上进行测试,因为这些都是纯 Google 的,因此任何问题均由 Google 负责。我同意 .gpx
是 GPX 内容的常见文件扩展名,因此 ACTION_OPEN_DOCUMENT
和 application/gpx+xml
应该允许用户选择它内容。
Is there a way to create a custom mime type of "application/gpx", just for use in my app?
不,抱歉,至少不会影响 ACTION_OPEN_DOCUMENT
。
Maybe I could change the file extension associated with the "application/gpx+xml" mimne type?
不,抱歉,除了我建议的错误报告之外。
is there another way to accomplish what I want to do?
不完全是。
关于java - 如何为 ACTION_OPEN_DOCUMENT Intent 实现自定义 MIME 类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59968229/