10

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:

<data android:scheme="file" android:mimeType="*/*" android:pathPattern="*.*\\.myFileExt" />
<data android:scheme="content" android:mimeType="*/*" android:pathPattern="*.*\\.myFileExt" />  

It kinda works. Let me explain. I have a file in my gmail( sent a file to my self ), which has the proper extension, so when I download it from my phone's browser and click open, it opens my application correctly, but if I explore to that file path; where the file is located, and try to open it, my phone says no application can open this file-type.

Any ideas on how to solve this problem?

dchhetri
  • 6,926
  • 4
  • 43
  • 56
  • maybe an issue with your file explorer... – Smugrik Aug 11 '11 at 18:45
  • I see the same thing. I'm interested to see if there's an answer. I don't know what @user814628 is using, but I have the same issue on CM7 – Earl Aug 11 '11 at 18:46
  • Testing on galaxy tablet, and I don't think its an issue with file explorer, I'm using the native file explorer(i.e myFiles) folder that comes with the software to navigate through files – dchhetri Aug 11 '11 at 18:50
  • Your filter-snippet is too short. You should have included the whole – Robert Siemer May 09 '13 at 16:23

3 Answers3

5

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>
Rene
  • 4,033
  • 2
  • 24
  • 29
1

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.

Robert Siemer
  • 32,405
  • 11
  • 84
  • 94
1

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.

Muzikant
  • 8,070
  • 5
  • 54
  • 88
  • Thanks but that did not work for some reason. For example a typical filename that I use is, filename.myFileExt. The location of where it exist doesn't matter right? This shouldn't be happening, I don't know why it is though. – dchhetri Aug 18 '11 at 17:17
  • 2
    This is insane. On top, a literal dot would be `\\.` – Try to put all attributes in the same data-element. – Robert Siemer May 09 '13 at 17:31
  • 1
    @RobertSiemer do you mean something like this `.*\\.AAA` ? – Muzikant Aug 27 '13 at 09:28
  • Yes. – And after reducing it to one pathPattern, put it in one single ``. – If I recall it right, the Android docs seem to suggest splitting it up in several data-elements in one place in the documentation (which I believe is wrong). – Robert Siemer Sep 03 '13 at 16:45
  • found any solution ? – Web.11 Apr 28 '21 at 11:54