Downloading attachment from g/email in Android

2019-09-03 07:59发布

问题:

I want to download custom files from email to my app. I used intent filters below as suggested by Richard Legget. The app works fine in the Eclipse VM and downloads the file, but won't work when installed on Nexus 7 (Kit Kat) or Acer (ICS) tablets. The View button shows up on the email attachment in the VM but not on the real tablets. Any ideas would be appreciated.

        </intent-filter>  
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data
                android:host="*"
                android:mimeType="application/fdh"
                android:pathPattern=".*\\.fdh" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />

            <data
                android:host="*"
                android:mimeType="application/octet-stream"
                android:pathPattern=".*\\.fdh" />
        </intent-filter> 

Solved it with help from @Sergey. My custom file is in fact XML format so I now save as an xml file and use this:-

            <category android:name="android.intent.category.DEFAULT" />

            <data
                android:host="com.mydomain.myapp"
                android:mimeType="text/xml"
                android:pathPattern=".*\\.xml" />
        </intent-filter>   

回答1:

GMail doesn't let you click URL's with unknown schemes, so you can use the schema that beginning with "http://". To define in manifest do something like this:

<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:host="com.yourdomain.yourapp"/>
</intent-filter>