简体   繁体   English

Android - 用我的应用程序打开Gmail附件

[英]Android - Opening gmail attachment with my App

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. 当文件在我的SD卡中时,我能够使用Intent过滤器完成此操作。 I can also view the 'download' and 'preview' buttons if the file is sent as a Gmail attachment. 如果文件作为Gmail附件发送,我还可以查看“下载”和“预览”按钮。 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. https://play.google.com/store/apps/details?id=com.hwkrbbt.downloadall&hl=en然后,当我点击Gmail中的下载按钮时,建议下载所有文件和我的应用程序以下载文件。 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>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM