我需要使用我的应用打开带有自定义扩展名的文件。当文件在我的SD卡中时,我可以使用Intent过滤器来执行此操作。如果文件是作为Gmail附件发送的,我还可以查看“下载”和“预览”按钮。但是,当我单击下载/预览按钮时,收到消息“对不起,附件无法下载” 。
我以为这是我的应用程序出现的问题。但是我有一个主意,并在手机上安装了“下载所有文件”应用程序。
https://play.google.com/store/apps/details?id=com.hwkrbbt.downloadall&hl=en
然后,当我单击Gmail中的下载按钮时,建议同时下载所有文件和我的应用程序来下载文件。我选择了我的应用,一切正常!
这是一些安全问题吗?
这些是我的 Intent 过滤器:
<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 标签。
<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>
最佳答案
我自己弄清楚了,所以我发布解决方案,以防万一其他人遇到这个奇怪的问题。
意向过滤器需要内容类型和文件方案类型,以及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"/>
关于Android-使用我的应用程序打开Gmail附件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13431479/