Android intent-filter - custom extension

579 Views Asked by At

I've been weeding through SO trying to find a solution for this but to no avail. I've successfully set my app up so that when tapping on it's data file my app is a choice to open it (if not opened automatically). The issue is that other file types are also being given the option to 'open with my app', which is easily blocked once my app is started, but I'd like to remove that option all together.

I've tried changing the pathPattern to something very specific, as this should be the only filename ever used: "file.fakeapp" but my app still tries to open any file, regardless of name or ext.

Here is my intent-filter:

        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data
                android:scheme="content" 
                android:pathPattern="file.fakeapp" 
                android:mimeType="application/octet-stream"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data 
                android:scheme="file" 
                android:mimeType="*/*"     
                android:pathPattern="file.fakeapp"/>
        </intent-filter>

I suspect the issue is due to the file scheme, mimeType "*/*" but if I make this anything else my app is not an option to open the custom file type. So it seems as though I'm in an all-or-nothing situation. The file type is actually just sqlite but has a custom extension.

Any help is greatly appreciated.

1

There are 1 best solutions below

4
On BEST ANSWER

The documentation indicates that the value of pathPattern is ignored if scheme and host are not present. Try adding:

<data android:host="*" />

Also look at this related SO post and answer.