从 Android 上的 Gmail 应用程序下载附件的意图过滤器 [英] Intent filter to download attachment from gmail apps on Android

查看:30
本文介绍了从 Android 上的 Gmail 应用程序下载附件的意图过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有带有意图过滤器 (ACTION_VIEW) 的 android 应用程序来打开文件并将其导入到我的应用程序中.我希望将文件附件从 gmail 应用程序下载到我的应用程序中.一些文件类型(即 jpg、png、txt)被正确保存,但有些则不是(即 doc、xls、ppt).我相信我的活动有正确的意图过滤器,因为它适用于其他应用程序(即 Dropbox),但不适用于 Gmail 应用程序.有什么解决办法吗?

I have android application with intent filter (ACTION_VIEW) to open file and import it into my application. I wish to download file attachment from gmail app into my application. Some of file type (i.e. jpg, png, txt) are saved correctly, but some are not (i.e doc, xls, ppt). I believe I have the correct intent filter for my activity since it works from other app (i.e. dropbox), but not gmail app. Is there any solution for this ?

推荐答案

通过删除我的意图中的方案数据过滤器(删除方案行并给它试一试):

I was able to make the download and preview buttons pop up on Android in GMail by removing the scheme data filter in my intent (delete the scheme line and give it a try):

<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="file" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\.ext" />
<data android:host="*" />
</intent-filter>

但是,根据 Android 文档,如果未为意图过滤器指定方案,则忽略所有其他 URI 属性."移除了 scheme 和 URI 属性后,过滤意图的唯一其他方法是使用 Mime 类型,我们都知道自定义文件扩展名没有注册的 mime 类型.

However, as per the Android documentation, "If a scheme is not specified for the intent filter, all the other URI attributes are ignored." With the scheme and URI attributes removed, the only other way to filter the intents is using Mime type, and we all know that custom file extensions do not have registered mime types.

作为参考,URI 的格式如下:

For reference, URI are of the form:

  • scheme://host:port/path
  • 路径前缀
  • 路径模式

因此,如果没有计划,所有这些都会下降.发现上述内容后,我尝试了显而易见的 - 使用"* "作为方案,甚至尝试过".* ".这些都没有奏效.我希望其他人可以建立我的试验.但我相信这与选择正确的方案有关.不幸的是,我所知道的唯一方案是 http https 内容和文件,以上都不是灵丹妙药.

So without a scheme, all of that drops. After discovering the above, I tried the obvious -- use a " * " for the scheme, and even tried " .* ". Neither of those worked. I hope someone else can build off my trials. But I believe it has to do with selecting the correct scheme. Unfortunately, the only schemes I know of are http https content and file, and none of the above are the magic bullet.

:::::::

我昨天解决了这个问题.请参阅我的解决方案:

I solved this yesterday. Please see my solution:

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/*" host="*" android:pathPattern=".*.ext" android:scheme="content" />
</intent-filter>

此意图将导致 gmail 显示下载"/预览"按钮.事实上,当 .ext 文件也作为附件发送到常规电子邮件客户端时,这也会导致您的应用打开.

This intent will cause gmail to display the Download / Preview buttons. In fact, this will also cause your app to open when .ext files are sent as attachments to the regular email client as well.

这篇关于从 Android 上的 Gmail 应用程序下载附件的意图过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆