Add file extension filter in a browsable app

188 Views Asked by At

I want to add a file extension filter to my browsable app because I want it to be browsable only when the url points to an image (jpg, png, bmp, gif...)

I have tried android:mimeType="image/*" but it doesn't work with internet urls, it only works if it directly points to an image in the file system (using file://)

Is there a way to filter a url by file extension such as http://dmoral.es/assets/image/diffie_hellman.png?

This is my intent-filter in manifest:

<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:mimeType="image/*" />
</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="https" android:mimeType="image/*" />

</intent-filter>

It works as a browsable app if I remove the mimeType filter, with the filter added it doesn't act as a browsable app.

1

There are 1 best solutions below

0
On

Finally I managed to make it work using pathPattern as seen here.

<data android:scheme="https"
                android:host="*"
                android:pathPattern=".*\\.jpg"/>
<data android:scheme="https"
                android:host="*"
                android:pathPattern=".*\\.jpeg"/>
<data android:scheme="https"
                android:host="*"
                android:pathPattern=".*\\.png"/>
<data android:scheme="https"
                android:host="*"
                android:pathPattern=".*\\.bmp"/>
<data android:scheme="https"
                android:host="*"
                android:pathPattern=".*\\.gif"/>

(Both for https and http)