Android 具有一个活动的多个文件扩展名/mimetype意图筛选器
先生们 我正试图得到它,这样我的Android应用程序就可以响应打开的文件(通过匹配扩展名)和mime类型(这样它们就可以在浏览器中工作) 我遵循了这里的建议: 但还是没有运气 我的android清单文件的相关部分如下:Android 具有一个活动的多个文件扩展名/mimetype意图筛选器,android,android-intent,android-manifest,Android,Android Intent,Android Manifest,先生们 我正试图得到它,这样我的Android应用程序就可以响应打开的文件(通过匹配扩展名)和mime类型(这样它们就可以在浏览器中工作) 我遵循了这里的建议: 但还是没有运气 我的android清单文件的相关部分如下: <activity android:name="MuPDFActivity" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitle
<activity android:name="MuPDFActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="application/vnd.ms-xpsdocument"/>
</intent-filter>
<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:mimeType="application/x-cbz"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="file"/>
<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.xps"/>
<data android:host="*"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="file"/>
<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.pdf"/>
<data android:host="*"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="file"/>
<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.cbz"/>
<data android:host="*"/>
</intent-filter>
</activity>
如您所见,我希望该应用程序能够被调用用于.pdf、.xps和.cbz文件,以及具有相关mimetype的文件。这里的本地测试似乎表明.pdf和application/pdf部分都在工作,但尽管我可能尝试一下,.xps(大概还有.cbz)部分都不工作
我是不是漏掉了什么明显的东西?每个活动只能有一个mimetype/文件模式吗
任何帮助都将不胜感激
谢谢
罗宾
每个活动只能有一个mimetype/文件模式吗
没有。据你自己承认,有两个正在工作(PDF x 2)
我是不是漏掉了什么明显的东西
我怀疑
BROWSABLE
元素是否会对您所使用的组件有多大好处,而其他组件则需要它BROWSABLE
适用于浏览器,它将沿着MIME类型路径运行。afaik,这更像是这样(一个具有不同值的过滤器):
此外,mime类型是否可能不正确?多个
是逻辑或,并单独处理。因此,您有一个带有android:scheme
但没有android:pathPattern
的标签,还有一个带有android:pathPattern
但没有android:host
的标签,以此类推。因此,没有一个
标记是完整的,也不会有任何好处
你应使用:
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:scheme="file"
android:mimeType="*/*"
android:pathPattern=".*\\.cbz"
android:host="*"
></data>
</intent-filter>
您可以有第二个
,但它需要再次使用所有四个属性,因为如果您想使用Android:pathPattern
,这四个属性在Android 4中都是必需的。(他们没有使用较旧的Android版本)哪个Android版本?我注意到这里有不同之处。看我的问题:有趣。我曾经尝试将android:mimeType
和android:pathPattern
组合在一起,但没有成功。对于android:pathPattern
而言,
标记的所有四个属性都需要在android 4中设置。所以你的提示对操作没有帮助。嗨,马丁,如果我使用上面的意图过滤器,当我试图从通知打开gmail应用程序时,我的应用程序正在显示。组合多个标记有效吗?它只为我检测到第一个。
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:scheme="file"
android:mimeType="*/*"
android:pathPattern=".*\\.cbz"
android:host="*"
></data>
</intent-filter>