如何做到从Android的2意向过滤器更换到Android 4? [英] How did intent-filter change from Android 2 to Android 4?
问题描述
我有以下意图过滤器在我的AndroidManifest.xml这工作得很好Android中2.xx的,不会做的Android 4.xx的东西:
I have the following intent-filter in my AndroidManifest.xml which works perfectly well in Android 2.x.x and does not do anything in Android 4.x.x:
<intent-filter
android:icon="@drawable/ic_fx_603p_pf"
android:label="FX-603P Program File"
android:priority="1"
>
<category
android:name="android.intent.category.DEFAULT"
></category>
<action
android:name="android.intent.action.VIEW"
></action>
<data
android:host="*"
android:pathPattern=".*\\.pf"
android:scheme="file"
></data>
</intent-filter>
现在的问题是:什么都有变化,我该怎么做的意图再次工作
The question is: What has changes and how can I make the intent work again?
预期的行为:在选择与文件* PF
扩展的文件管理器(如天文)我的应用程序应该被启动,该文件应打开。另外,文件管理器应该使用我们提供的图标以可视化的文件。
The expected behaviour: In selecting a file with *.pf
extension in a file-manger (like Astro) my application should be started and the file should be opened. Also the file-manger should use us the provided icon to visualize the file.
推荐答案
:MIMETYPE 不是强制性的。因此该解决方案是:
Well after some experimenting I found out that android:mimeType
is not mandatory. Therefore the solution is:
<intent-filter
android:icon="@drawable/ic_fx_602p_pf"
android:label="FX-602P Program File"
android:priority="1"
>
<category
android:name="android.intent.category.DEFAULT"
></category>
<action
android:name="android.intent.action.VIEW"
></action>
<data
android:host=""
android:mimeType="*/*"
android:pathPattern=".*\\.pf"
android:scheme="file"
></data>
<data
android:host="*"
android:mimeType="application/x-fx-602p.program"
></data>
</intent-filter>
随着一点点额外的我发现了一个&LT;意向滤光器&gt;
可以拥有两个或多个&lt;数据&GT;
标签。如果任何一个比赛的目的是叫(逻辑OR)
As a little extra I found out that an <intent-filter>
can have two ore more <data>
tags. If either match the intent is called (logical OR)
在标签内的所有属性必须匹配(逻辑AND)。
Inside a tag all attributes must match (logical AND).
但没有与此解决方案的一个问题:它似乎没有在安卓2.x中的错误和&LT的属性;数据&GT;
不严格处理逻辑并导致所有文件被匹配时,安卓MIMETYPE
属性设置。不错啊,你不能两者兼得,将与未来去,如果是这样的话。
However there is a problem with this solution: It seems there is a bug in Android 2.x and the attributes of the <data>
are not strictly treated logical AND resulting in all files being matched when the android:mimeType
attribute is set. Ah well, you can't have it both ways and will go with the future if that is the case.
这篇关于如何做到从Android的2意向过滤器更换到Android 4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!