【问题标题】:Android - Opening gmail attachment with my AppAndroid - 使用我的应用程序打开 gmail 附件
【发布时间】:2012-11-17 14:27:11
【问题描述】:

我需要使用我的应用打开具有自定义扩展名的文件。当文件在我的 SD 卡中时,我可以使用 Intent 过滤器来执行此操作。如果文件作为 Gmail 附件发送,我还可以查看“下载”和“预览”按钮。但是,当我单击下载/预览按钮时,我收到了消息 - “抱歉,无法下载附件”

我认为这是我的应用程序的问题。但我有一个随机的想法,并在我的手机上安装了“下载所有文件”应用程序。 https://play.google.com/store/apps/details?id=com.hwkrbbt.downloadall&hl=en 然后,当我单击 Gmail 中的下载按钮时,建议下载所有文件和我的应用程序来下载文件。我选择了我的应用程序,一切正常!!

这是一些安全问题吗? 这些是我的意图过滤器:

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

编辑:这是完整的活动标签。

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

【问题讨论】:

  • 你试过android:host="gmail-ls"吗?

标签: android


【解决方案1】:

我自己想通了,所以我发布了解决方案,以防其他人遇到这个奇怪的问题。

intent 过滤器需要内容和文件方案类型,使用 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"/>

【讨论】:

  • Hi Blue,你能分享完整的 标签吗?
  • 我已经尝试过这个解决方案并且它有效,但它具有误导性,因为pathPattern 将被忽略。 pathPattern 属性将被忽略,除非还为过滤器指定了 schemehost 属性(您的答案缺少 host 属性)。有关 pathPattern 属性,请参阅 documentation。我在实践中也看到了这一点。意图过滤器将处理任何附件,而不仅仅是具有指定文件扩展名的附件。
  • @Manju,你为什么不把完整的解决方案放在你的答案中,而不是放在问题中?那不是更有意义吗?另外,您为什么在答案中使用不同的扩展名?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-04
  • 1970-01-01
  • 2011-06-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多