How did intent-filter change from Android 2 to Android 4?

前端 未结 1 944
清酒与你
清酒与你 2021-01-25 06:30

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:

  

        
相关标签:
1条回答
  • 2021-01-25 06:55

    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>
    

    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)

    Inside a tag all attributes must match (logical AND).

    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.

    0 讨论(0)
提交回复
热议问题