views:

3140

answers:

3

I want to be able to download a file with a particular extension from the 'net, and have it passed to my application to deal with it, but I haven't been able to figure out the intent filter. The filetype is not included in the mimetypes, and I tried using

<data android:path="*.ext" />

but I couldn't get that to work.

+1  A: 

You probably can't do it system wide, because Android doesn't support that. You can do this for specific apps like Google mail client or Google browser.

Look for more info hire: http://www.mail-archive.com/[email protected]/msg47862.html

I saw code for adding support for APKs in mail client (for installing them instead of saving), but unfortunately I cant found it now.

Maciek Sawicki
+5  A: 

Rather than android:path, try android:mimeType, with a value of the MIME type of this particular piece of content. Also, android:path does not accept wildcards -- use android:pathPattern for that.

CommonsWare
"The filetype is not included in the mimetypes"? There should still be a mimetype for the type of content you're downloading, even if it doesn't use the same word.
Klondike
There is a mimetype for the type of content, but the file is produced by a third party application that puts a different extension on it, so I don't think it will be recognised as that mimetype.
Curyous
Thanks, I'll give the pathPattern a go and see what happens.
Curyous
+3  A: 

Here is how I defined my activity in my AndroidManifest.xml to get this to work.

<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=".*\\.kdb" />
        <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 .kdb). 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.

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 .kdb flie 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.

Brian Pellin
Wow, that's awesome, thanks, I'll try it out.
Curyous