Associating certain file extension to my android application

后端 未结 3 1376
太阳男子
太阳男子 2020-12-10 05:00

I\'m having trouble associating my custom file extension to my android application that I am developing. In my android manifest file I have the following:

&l         


        
相关标签:
3条回答
  • 2020-12-10 05:40

    Your filter-snippet is too short to check it for errors. You should have included the whole <intent-filter>.

    One mistake is in your pathPattern: it can’t start with an asterisk, e.g. *.* is wrong. That crappy Android glob matching here handles . and .* and x* only (the last one matches “”, “x” ... and “xxxxxx”, ...)

    Furthermore, the “host” attribute is missing. pathPattern is meaningless if scheme or host are missing.

    0 讨论(0)
  • 2020-12-10 05:41

    Some cases are kinda tricky, I've settled on using:

        <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=".*\\.myFileExt" />
            <data android:host="*" />
        </intent-filter>
    

    and this sometimes fails because sometimes only a more global mime type (in my case XML) is used:

        <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/xml" />
        </intent-filter>
    
    0 讨论(0)
  • 2020-12-10 05:48

    After spending a few hours on this issue I finally came up with this solution (AAA is the file extension):

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="*/*" />
        <data android:scheme="file" />
        <data android:host="*" />
        <data android:port="*" />
        <data android:pathPattern=".*..*..*..*..*.AAA" />
        <data android:pathPattern=".*..*..*..*.AAA" />
        <data android:pathPattern=".*..*..*.AAA" />
        <data android:pathPattern=".*..*.AAA" />
        <data android:pathPattern=".*.AAA" />
    </intent-filter>
    

    The reason for all of those pathPattern is that if you have a dot in your file name the general form of .*.AAA will not match the filename.

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