1

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.

Grender
  • 1,589
  • 2
  • 17
  • 44
  • "but it doesn't work with internet urls" -- please provide a [mcve]. – CommonsWare May 02 '16 at 17:22
  • I have edited the answer. – Grender May 02 '16 at 17:23
  • That is not a [mcve] demonstrating your problem with `android:mimeType="image/*"`. – CommonsWare May 02 '16 at 17:24
  • Added my `intent-filter` code – Grender May 02 '16 at 17:29
  • OK. What is the user action that you are expecting will trigger these? For example, if you are expecting the user to click on a link in a browser, the browser may elect to handle the link itself for MIME types that it recognizes, rather than search for alternative apps that can view the content. – CommonsWare May 02 '16 at 17:30
  • It's for this app: [Tappic](https://play.google.com/store/apps/details?id=es.dmoral.tappic), I want my app to appear as a browsable one only if the url clicked is pointing to an image. Now it prompts on every clicked link. – Grender May 02 '16 at 17:32
  • You should discuss this with the authors of that app, then, to see how you can better integrate with it. Your plan of using file extensions is unreliable, as there is no requirement for an image URL to have a recognizable file extension. – CommonsWare May 02 '16 at 17:35
  • I'm the author of that app. – Grender May 02 '16 at 17:36

1 Answers1

1

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)

Community
  • 1
  • 1
Grender
  • 1,589
  • 2
  • 17
  • 44