0

I noticed one of the big video apps on Android has all sorts of path patterns, I'm assuming to catch subdirectories or weird names? they basically end up having a bunch of pattersn that look like this: <data android:pathPattern=".*..*..*..*..*..*..*..*..*..*..*..*..*..*..*.3gp" />

Is there no easier way to simplify that path?

Here is a longer example:

</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="http" android:host="*" />
                <data android:pathPattern=".*.3gp" />
                <data android:pathPattern=".*..*.3gp" />
                <data android:pathPattern=".*..*..*.3gp" />
                <data android:pathPattern=".*..*..*..*.3gp" />
                <data android:pathPattern=".*..*..*..*..*.3gp" />
                <data android:pathPattern=".*..*..*..*..*..*.3gp" />
                <data android:pathPattern=".*..*..*..*..*..*..*.3gp" />
                <data android:pathPattern=".*..*..*..*..*..*..*..*.3gp" />
                <data android:pathPattern=".*..*..*..*..*..*..*..*..*.3gp" />
                <data android:pathPattern=".*..*..*..*..*..*..*..*..*..*.3gp" />
                <data android:pathPattern=".*..*..*..*..*..*..*..*..*..*..*.3gp" />
                <data android:pathPattern=".*..*..*..*..*..*..*..*..*..*..*..*.3gp" />
                <data android:pathPattern=".*..*..*..*..*..*..*..*..*..*..*..*..*.3gp" />
                <data android:pathPattern=".*..*..*..*..*..*..*..*..*..*..*..*..*..*.3gp" />
                <data android:pathPattern=".*..*..*..*..*..*..*..*..*..*..*..*..*..*..*.3gp" />
casolorz
  • 8,486
  • 19
  • 93
  • 200
  • Looks like they wanted to retrieve every .3gp file in every folder and decided to hack together a fast solution rather than creating anything scalable. So, if they add a few subdirectories, their code breaks, and if they decide to change their file format, it'll break. I'm not fluent enough in android to provide an answer, but this is definitely a duct tape solution I would avoid. – Aarowaim Mar 23 '14 at 20:39
  • I figured that is what they are doing, I'm just trying to find out of there is a way to catch all possible paths before the extension. – casolorz Mar 23 '14 at 20:42
  • http://developer.android.com/guide/topics/manifest/data-element.html this suggests that they may be looking for paths in the format of (0-n characters).(0-n characters).(0-n characters). For example `movies.brian.home.bruce.almighty.2000`. It seems like it may be redundant, unless the dot character (.) refers to a sub-directory. If it does not, you could reduce it into the first pathPattern only. – Aarowaim Mar 23 '14 at 20:46

1 Answers1

1

Reference

<activity name="com.keepassdroid.PasswordActivity">
    <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=".*\\.3gp" />
        <data android:host="*" />
    </intent-filter>
</activity>

The scheme of file indicates that this should happen when a local file is opened (rather than protocol like HTTP).

mimeType can be set to */* to match any mime type.

pathPattern is where you specify what extension you want to match (in this example .3gp). The .* at the beginning matches any squence of characters. These strings require double escaping, so \\. matches a literal period. Then, you end with your file extension. One caveat with pathPattern is that .* is not a greedy match like you would expect if this was a regular expression. This pattern will fail to match paths that contain a . before the .3gp. For a more detailed discussion of this issue and a workaround see here

Finally, according to the Android documentation, both host and scheme attributes are required for the pathPattern attribute to work, so just set that to the wildcard to match anything.

Now, if you select a .3gp file in an app like Linda File Manager, my app shows up as an option. I should note that this alone does not allow you to download this filetype in a browser, since this only registers with the file scheme. Having an app like Linda File Manager on your phone resisters itself generically allowing you to download any file type.

Community
  • 1
  • 1
kAnNaN
  • 3,669
  • 4
  • 28
  • 39