XML 个文件的 Intent 过滤器
Intent Filter for XML files
我希望能够在用户尝试打开 xml 文件时在我的应用程序中打开 XML 文件。有很多类似的问题,但我已经尝试了很多,但似乎没有任何帮助。
当我将这些 Intent 过滤器用于 PDF 文件时,它可以完美地工作(对于 PDF),但是当我将 'pdf' 的两个提及替换为 'xml' 时,它不适用于 XML 文件,即使这些文件位于同一文件夹中。
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/pdf" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file"
android:host="*"
android:pathPattern=".*\.pdf" />
</intent-filter>
您有两个 <intent-filter>
个元素。
第一个依赖于 MIME 类型。 application/xml
可能是 XML 文件的 MIME 类型,但 text/xml
也是。并且,对于某些 XML 文件,可能会根据 XML 的内容使用另一种 MIME 类型(例如,application/atom+xml
用于使用 Atom 模式编写的内容)。文件管理器和其他 "generic" 内容管理器将倾向于使用 MimeTypeMap
报告的文件扩展名的任何 MIME 类型。其他应用程序,例如电子邮件客户端和 Web 浏览器,将使用服务器报告的 MIME 类型。
第二个依赖于方案 (file
) 和文件扩展名 (.xml
)。 file
方案正在慢慢消失,因此这个特定的 <intent-filter>
将来不会用得太多。
就我而言 application/xhtml+xml
解决了我的问题。
我希望能够在用户尝试打开 xml 文件时在我的应用程序中打开 XML 文件。有很多类似的问题,但我已经尝试了很多,但似乎没有任何帮助。
当我将这些 Intent 过滤器用于 PDF 文件时,它可以完美地工作(对于 PDF),但是当我将 'pdf' 的两个提及替换为 'xml' 时,它不适用于 XML 文件,即使这些文件位于同一文件夹中。
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/pdf" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file"
android:host="*"
android:pathPattern=".*\.pdf" />
</intent-filter>
您有两个 <intent-filter>
个元素。
第一个依赖于 MIME 类型。 application/xml
可能是 XML 文件的 MIME 类型,但 text/xml
也是。并且,对于某些 XML 文件,可能会根据 XML 的内容使用另一种 MIME 类型(例如,application/atom+xml
用于使用 Atom 模式编写的内容)。文件管理器和其他 "generic" 内容管理器将倾向于使用 MimeTypeMap
报告的文件扩展名的任何 MIME 类型。其他应用程序,例如电子邮件客户端和 Web 浏览器,将使用服务器报告的 MIME 类型。
第二个依赖于方案 (file
) 和文件扩展名 (.xml
)。 file
方案正在慢慢消失,因此这个特定的 <intent-filter>
将来不会用得太多。
就我而言 application/xhtml+xml
解决了我的问题。