Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Opening gmail attachment with my App

Tags:

android

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>
like image 944
Manju Avatar asked Nov 17 '12 14:11

Manju


People also ask

How do I change my attachment opening settings in Gmail on Android?

Click Settings>Apps>Default apps>Choose default app by file type.

How do I change how Gmail opens attachments?

Steps to Configure Attachment Compliance in GmailScroll down to Advanced settings and click on it. Scroll down to Attachment compliance and hover on it and to see configure option and click on it. Select the messages that you want to affect.

Why can't I open attachments in Gmail on my Android phone?

Why can't I see attachments in Gmail on phone? Try clearing the GMail app cache (and data if necessary). There are different paths for this on different phones: Open the Settings app, then go to Storage & USB > Apps > Gmail. Open the Settings app, then go to App Management > Gmail > Storage Usage.

Why can't I open an email attachment on my phone?

If you're unable to open a specific email attachment please first ask the person who sent the email what format the attached file is in: Android cannot read all file types. Click here to see a table of the supported media formats for the different Android versions.


1 Answers

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"/>

like image 74
Manju Avatar answered Oct 31 '22 04:10

Manju