如何为 ACTION_OPEN_DOCUMENT 意图实现自定义 MIME 类型?

How to implement a custom MIME type for ACTION_OPEN_DOCUMENT intent?

我正在使用 ACTION_OPEN_DOCUMENT 意图来启动系统文件选择器。用户应该选择 "gpx" 文件 (blabla.gpx)。

我想让选取器只允许选择扩展名为“.gpx”的文件。

有 "application/gpx+xml" 的 MIME 类型,但是当我在 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_DOCUMENTapplication/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?

不是真的。

我向 Google 报告了此事,这是他们的回复:

A coworker pointed out that application/gpx+xml is an established MIME type mapped to the file extension.gpx:

https://en.wikipedia.org/wiki/GPS_Exchange_Format

We'll consider adding this mapping to a future version of Android.

遇到 <input accept="application/gpx+xml"/> 不接受 .gpx 文件的问题。查找了 garmin connect 应用程序,因为我知道它正在运行,他们的解决方案非常适合我。

只需更改此 accept=".gpx,.tcx" 以及您希望支持的任何其他包含文件扩展名的 gps。