views:

37

answers:

1

I want to have the default android browser be able to download files of a particular file extension, .xyz, for example.

Without installing Astro (or some other file manager), users will get the error "Cannot download. The content is not supported on this phone". Installing the Astro application allows the android browser to download any file to the sdcard.

How does it do that? I don't want users of my app to have to download Astro, but rather, just let the OS or browser know that it's okay to download files with the extension .xyz, because my app will handle them.

A: 

Add the appropriate entries to the manifest for you to respond to ACTION_VIEW Intents for that type of file. For example, this filter is for an activity that can view PDF files:

        <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="application/pdf" />
        </intent-filter>

With an appropriate <data> element, you could literally watch for .xyz files, though I think it will be better if you can watch for a MIME type instead.

CommonsWare
And this won't intercept a android.intent.action.VIEW intent with a http uri as data? I'd like the browser to do the download still.
Sancho
@Sancho: The application (e.g., Astro) advertising that it supports the MIME type downloads the files.
CommonsWare
So there's no way to let the browser know it's okay for the browser to download a file? All downloads must go through the application advertising the support for the file?
Sancho
@Sancho: "All downloads must go through the application advertising the support for the file?" -- correct.
CommonsWare
Hm. It turns out I was able to add a <data> element to the manifest of the non-browser app, and the browser did the download of the data type. Then when I clicked on that file in the downloads list, it launched the non-browser app. So, it seems the download didn't go through the application advertising support for the file. Anyway, this solution worked.
Sancho