android intent filter for custom file extension

前端 未结 1 2079
不知归路
不知归路 2020-12-20 03:27

I am trying to make an android app to open files with extension .abc and this is my application section from android manifest xml



        
相关标签:
1条回答
  • 2020-12-20 03:50

    First of all, the first intent-filter in your example uses MIME type image/jpeg. Is jpeg your .abc extension?

    I think there may be three reasons why this does not work:

    1. You need to add more MIME types. Try adding the following:

      <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:mimeType="application/abc"/>
      </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:mimeType="application/octet-stream"/>
      </intent-filter>
      

      And, if your .abc format is a text format:

      <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:mimeType="text/plain"/>
      </intent-filter>
      
    2. You have registered the file scheme. You might also need the content scheme:

      <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="content" />
          <data android:mimeType="*/*" />
          <data android:pathPattern=".*\\.abc" />
          <data android:host="*" />
      </intent-filter>
      
    3. Rumor has it that pathPattern with a dot only matches files containing a single dot. In your example, this would mean that your app would be associated with One.abc but not with Two.Dots.abc. Try adding more pathPatterns .*\\..*\\.abc, .*\\..*\\..*\\.abc etc.:

      <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=".*\\..*\\.abc" />
          <data android:host="*" />
      </intent-filter>
      
    0 讨论(0)
提交回复
热议问题