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

1 回答 1

9

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

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

于 2012-11-18T15:58:07.867 回答