Phil
Phil

Reputation: 36289

How can I specify an intent filter to recognize jpg files, but not jpeg in Android?

Basically, I want my app to be able to open JPG or jpg files, but not files with the file extension JPEG or jpeg. This is what I have for intent filters, but it is also accepting JPEG and jpeg:

<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="content" android:mimeType="application/octet-stream" android:pathPattern=".*\\.jpg" />
    <data android:scheme="file" android:mimeType="application/octet-stream" android:pathPattern=".*\\.jpg" />
</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="file" android:pathPattern=".*\\.jpg" />
</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="content" android:mimeType="application/octet-stream" android:pathPattern=".*\\.JPG" />
    <data android:scheme="file" android:mimeType="application/octet-stream" android:pathPattern=".*\\.JPG" />
</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="file" android:pathPattern=".*\\.JPG" />
</intent-filter>
<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <data android:mimeType="image/jpg" android:pathPattern=".*\\.jpg"/>
</intent-filter>
<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <data android:mimeType="image/jpg" android:pathPattern=".*\\.JPG"/>
</intent-filter>

How can I improve this intent filter to handle only specific image file extensions?

Upvotes: 1

Views: 1983

Answers (1)

Sanders
Sanders

Reputation: 448

You're capturing JPEG images because you specified the android:mimeType of image/jpg, which JPEG images fit. Remove that tag from your <data> element and just specify android:pathPattern.

Upvotes: 1

Related Questions