我希望我的应用程序能够打开包含 XML 内容的 .src
文件。它部分起作用;有一个问题我无法解决:看起来 Android 在匹配 Intent 时没有考虑 android:pathPattern
。我的 intent-filter
看起来像这样:
<intent-filter>
<action android:name="com.google.android.apps.drive.DRIVE_OPEN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:host="*" android:mimeType="text/xml" android:pathPattern=".*\\.src" />
<!-- path pattern does not match dots correctly: http://stackoverflow.com/q/3400072/44089 -->
<data android:pathPattern=".*\\..*\\..*\\.src" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.src" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.src" />
</intent-filter>
在我添加 android:mimeType="text/xml"
之前,实际上每个“查看”操作都与我的应用程序匹配,即我的应用程序在应用程序选择器中可见,即使我想查看联系人。幸运的是,添加 mimeType
过滤有点帮助。但是,pathPattern
似乎并没有改变我的 Intent 过滤的工作方式。
我看过几十篇关于这个的教程,代码都是一样的。这一定是一些奇怪的、不寻常的案例。我究竟做错了什么?如果有任何想法或建议,我将不胜感激。
最佳答案
引用 the documentation for android:path*
attributes :
These attributes are meaningful only if the scheme and host attributes are also specified for the filter.
你似乎没有计划。
关于Android 的 intent-filter 匹配文件而不考虑其扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26314927/