在Android中从g / email下载附件

时间:2014-04-22 16:37:53

标签: android eclipse android-intent

我想将自定义文件从电子邮件下载到我的应用中。我使用Richard Legget建议的下面的意图过滤器。该应用程序在Eclipse VM中运行良好并下载文件,但在安装在Nexus 7(Kit Kat)或Acer(ICS)平板电脑上时无法正常工作。 “查看”按钮显示在VM中的电子邮件附件中,但不显示在真实平板电脑上。任何想法都将不胜感激。

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

在@Sergey的帮助下解决了这个问题。我的自定义文件实际上是XML格式,所以我现在保存为xml文件并使用它: -                 

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

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

1 个答案:

答案 0 :(得分:1)

GMail不允许您使用未知方案单击URL,因此您可以使用以“http://”开头的架构。 要在清单中定义,请执行以下操作:

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