0

I have an attachment with a custom extension (say .abc) whose mimeType I'm unaware of. I would want to open this attachment using my Android application. I tried adding the code below to the manifest but that didn't seem to help. I did go through multiple Stack Overflow posts but none seem to work and those that do also expose my app to other extensions and not just .abc

        <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="*/*" />
            <data android:pathPattern="*.*\\.abc" />
            <data android:host="*"/>
        </intent-filter>
Wayne Koorts
  • 10,861
  • 13
  • 46
  • 72
lokoko
  • 5,785
  • 5
  • 35
  • 68
  • 1
    Have you looked at this question ? http://stackoverflow.com/questions/7030832/associating-certain-file-extension-to-my-android-application – Muzikant Aug 26 '13 at 14:56

2 Answers2

3

There's an opening * in your pathPattern. Any reason for that? It shouldn't be a lead character, since it only affects the preceding character.

From the Android docs:

  • An asterisk ('*') matches a sequence of 0 to many occurrences of the immediately preceding character.

  • A period followed by an asterisk (".*") matches any sequence of 0 to many characters.

You may also want to add an android:scheme element. From the same section as above:

These attributes are meaningful only if the scheme and host attributes are also specified for the filter.

Also, here's a near duplicate you can read through, with a widely accepted answer.

Community
  • 1
  • 1
Geobits
  • 22,218
  • 6
  • 59
  • 103
  • Hey tnks. The issue is that path pattern applies only for files stored on local storage. Also, unless there is a mimeType specified, it is accessible by other apps as well. – lokoko Aug 22 '13 at 19:58
  • The path pattern doesn't discriminate between local/remote. Remove the leading `*` and it should match anything ending in ".abc"(unless it has an intermediate `.`, which is an unfortunate implementation of android's `PatternMatcher`). As for "accessible by other apps", I'm not sure what you mean. Are you trying to make it so that your app is the *only* app that can open a certain file type? If so, that won't work. The intent system doesn't work that way. – Geobits Aug 22 '13 at 20:06
  • The *scheme* used in the other answer is what distinguishes between local and remote, btw. – Geobits Aug 22 '13 at 20:07
  • I tried to change it to accept ".abc" but it accepts it for ".abc" and ".abc*" for some reason. Any suggestions ? – lokoko Aug 23 '13 at 10:58
  • Have you tried `".*\\.abc"`? The opening `.*` means "any amount of any leading character(s)". The `\\.` is an escaped(literal) `.`, followed by characters `abc`. For more, you should read up on regular expressions. – Geobits Aug 23 '13 at 11:48
0

You need to specify android:scheme

<activity>
    <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:scheme="content" />
        <data android:host="*" />
        <data android:mimeType="*/*" />
        <data android:pathPattern=".*abc" />
        <data android:pathPattern=".*\\.abc" /> <!-- path includes one '.' -->
        <data android:pathPattern=".*\\..*\\.abc" /> <!-- path includes two '.' -->
        <data android:pathPattern=".*\\..*\\..*\\.abc" /> <!-- path includes three '.' -->
        <!-- repeat as long as you want -->
    </intent-filter>
</activity>
flx
  • 14,146
  • 11
  • 55
  • 70