11

I need to open files with custom extension using my app. I am able to do this using Intent filters when the file is in my sd card. I can also view the 'download' and 'preview' buttons if the file is sent as a Gmail attachment. However, when I clicked the download/preview buttons, I got the message - "Sorry, the attachment could not be downloaded".

I thought this was an issue with my app. But I had a random idea and installed "Download All Files" app on my phone. https://play.google.com/store/apps/details?id=com.hwkrbbt.downloadall&hl=en Then, when I click download button in Gmail, both Download All Files and My App are proposed for downloading the file. I chose my app, and everything works fine!!

Is this some security issue? These are my Intent Filters:

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

EDIT: Here's the full activity tag.

  <activity android:name=".TestApp"
              android:label="@string/app_name" 
              android:configChanges="orientation|keyboardHidden"
              android:launchMode="singleTask">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.TestApp.TestApp.NOTIFICATION" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <!-- Opening .ate file start -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="file" />
            <data android:host="*" />
            <data android:pathPattern=".*\\.ate" />
          </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:mimeType="*/*" />
         <data android:scheme="content" android:host="*"
            android:pathPattern=".*\\.ate" />
        <data android:scheme="file" android:host="*"
            android:pathPattern=".*\\.ate" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:scheme="file" android:pathPattern=".*\\.ate" android:mimeType="application/octet-stream"/>
        <data android:scheme="content" android:pathPattern=".*\\.ate" android:mimeType="application/octet-stream"/>
        </intent-filter>
        <!-- Opening .ate file end  -->
    </activity>
Manju
  • 251
  • 2
  • 9

1 Answers1

9

I figured it out myself, so I'm posting the solution, just in case someone else encounters this weird problem.

The intent filter requires both content and file scheme types, with the mimetype application/octetstream

<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="file" android:pathPattern=".*\\.inform" android:mimeType="application/octet-stream"/>
<data android:scheme="content" android:pathPattern=".*\\.inform" android:mimeType="application/octet-stream"/>

Manju
  • 251
  • 2
  • 9
  • Hi Blue, can you share the full tag please? – Giuseppe Dec 05 '12 at 15:41
  • 3
    I've tried this solution and it works, but it is misleading because the `pathPattern` will be ignored. The `pathPattern` attribute is ignored unless there is also a `scheme` and `host` attribute specified for the filter (Your answer is missing the `host` attribute). See the [documentation](http://developer.android.com/guide/topics/manifest/data-element.html) for the `pathPattern` attribute. I've also seen this in practice. The intent filter will handle any attachment and not just the attachments with the specified file extension. – Jacob Adams Dec 24 '13 at 03:39
  • What about **** and **** – IgorGanapolsky Oct 19 '17 at 16:24
  • @Manju, why don't you put the full solution in your answer, instead of in the question? Wouldn't that make more sense? Also, how come you're using a different extension in the answer? – ataravati May 13 '19 at 21:58