0

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.

Warblr
  • 1,188
  • 1
  • 13
  • 27
  • In your activity, have you tried getting the received intent using getIntent() and then examining its contents with getAction(), getCategories(), getScheme(), getDataString()? That data might offer some clues about how the filter match is occurring. Also, it's not clear from your post if you have both filters in your manifest at the same time, or you listed both just because you have tried each but neither worked. – Bob Snyder Jun 24 '15 at 21:02
  • Thanks for responding @qbix - both are in my manifest. Thanks for the tips I'll definitely start exploring from there. – Warblr Jun 24 '15 at 21:47

1 Answers1

2

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.

Community
  • 1
  • 1
Bob Snyder
  • 37,759
  • 6
  • 111
  • 158
  • Thanks again, @qbix - I'll try this out and report back. – Warblr Jun 24 '15 at 21:48
  • Ugh. I dislike when the issue was related to something I missed in the docs. You got it, @qbix -- needed to add host. Thank you! – Warblr Jun 24 '15 at 22:35
  • @Warbir The solution was easily overlooked. The matching rules are complicated. I was clued into the answer only after looking at the related issue and solution. Glad it worked for you. – Bob Snyder Jun 24 '15 at 23:17
  • Actually, I realized that once I put this in place everything started working as expected except for the gmail app. It no longer gave the option to use my app, instead trying to open the file with some random text application. I looked around and found http://stackoverflow.com/a/25663412/1542275 -- the response is marked as -1 but adding the intent-filter labeled "For catching attachments in Gmail:" in this solution to what I already had got things working exactly as I wanted. – Warblr Jun 24 '15 at 23:22