【问题标题】:How did intent-filter change from Android 2 to Android 4?意图过滤器如何从 Android 2 更改为 Android 4?
【发布时间】:2014-01-06 04:08:56
【问题描述】:

我的 AndroidManifest.xml 中有以下意图过滤器,它在 Android 2.x.x 中运行良好,在 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>

问题是:发生了什么变化,我怎样才能让意图再次起作用?

预期行为:在文件管理器(如 Astro)中选择扩展名为 *.pf 的文件时,我的应用程序应启动并打开文件。文件管理器也应该使用我们提供的图标来可视化文件。

【问题讨论】:

    标签: android android-intent android-manifest


    【解决方案1】:

    经过一些实验,我发现android:mimeType 不是强制性的。因此解决方案是:

      <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;intent-filter&gt; 可以有两个或更多&lt;data&gt; 标签。如果任一匹配,则调用意图(逻辑或)

    标签内的所有属性都必须匹配(逻辑与)。

    但是,此解决方案存在一个问题:Android 2.x 中似乎存在一个错误,并且 &lt;data&gt; 的属性未经过严格的逻辑 AND 处理,导致当 android:mimeType 属性为放。啊,好吧,你不能两全其美,如果是这样的话,你会和未来一起去。

    【讨论】:

    • 这是错误的。在我的手机(Nexus 5X And​​roid 7)上,这个: 匹配每个文件:/ .
    猜你喜欢
    • 1970-01-01
    • 2015-05-14
    • 1970-01-01
    • 2012-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    相关资源
    最近更新 更多