How to allow Android browser to download files of a certain extension?

I want the default Android browser to be able to download files of a specific .xyz file extension, for example.

Without installing Astro (or another file manager), users will receive the error message "Unable to download. Content is not supported on this phone." Installing the Astro app allows the Android browser to download any file to the SD card.

How it's done? I do not want users of my application to have to download Astro, but rather, just tell the OS or browser that everything is in order to download files with the extension .xyz, because my application will process them.

+3
source share
1 answer

Add the appropriate entries in the manifest to respond to ACTION_VIEW Intentsfor this 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>

Using the corresponding element, <data>you can literally monitor files .xyz, although I think it would be better if you look instead of the MIME type.

+1
source

Source: https://habr.com/ru/post/1760192/


All Articles