5

I have a custom file extension like .foo that I want to associate my app with. I created this 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:scheme="file" android:pathPattern=".*\\.foo"/-->
            <data android:scheme="file" android:mimeType="*/*"  android:pathPattern=".*\\.foo" android:host="*"/>
 </intent-filter>

The problem is that this doesn’t work on some devices. For example, only the following works with the Samsung Galaxy S3 (Android version: 4.4.2):

<data android:scheme="file" android:mimeType="*/*"  android:pathPattern=".*\\.foo" android:host="*"/>

However, with a LG G2 (Android version: 4.4.2), only this line works:

<data android:scheme="file" android:pathPattern=".*\\.foo"/>

To make it even worse, the Nexus 7 (Android-Version: 5.0) doesn’t seem to recognize custom file endings at all.

Has anyone ever had a similar problem and knows a solution?

2 Answers2

0

Patterns for files are screwy... seems to be on purpose done by the developers. It seems that the file pattern will work differently on different devices but it only depends on de depth of the file structure. See this link: pathPattern to match file extension does not work if a period exists elsewhere in the file name?

Community
  • 1
  • 1
eduyayo
  • 2,020
  • 2
  • 15
  • 35
  • 1
    Thank you for your advice. But this is definitely not the problem cause I have already tried your suggestion. – Agnes Klein Jan 13 '15 at 11:47
0

I think this way works for me (change "custom" with the extension you want to use) :

   <activity android:name=".MainActivity">
        <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=".*\\.custom"/>
            <!-- These additional pathPattern blocks are to allow for paths with
            additional periods in them. See:
            http://stackoverflow.com/questions/3400072/pathpattern-to-match-file-extension-does-not-work-if-a-period-exists-elsewhere-i/8599921 -->
            <data android:pathPattern=".*\\..*\\.custom"/>
            <data android:pathPattern=".*\\..*\\..*\\.custom"/>
            <data android:pathPattern=".*\\..*\\..*\\..*\\.custom"/>
            <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.custom"/>
            <data android:host="*"/>
        </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:scheme="file"/>
            <data android:pathPattern=".*\\.custom"/>
            <data android:pathPattern=".*\\..*\\.custom"/>
            <data android:pathPattern=".*\\..*\\..*\\.custom"/>
            <data android:pathPattern=".*\\..*\\..*\\..*\\.custom"/>
            <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.custom"/>
            <data android:host="*"/>
        </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/vnd.ni.custom" android:scheme="file"/>
        </intent-filter>
    </activity>
android developer
  • 114,585
  • 152
  • 739
  • 1,270