意图过滤器,以在Android的Gmail应用程序下载附件过滤器、意图、应用程序、下载附件

2023-09-13 00:41:20 作者:花颂

我有Android应用程序与意图过滤器(ACTION_VIEW)打开文件,并将其导入到我的应用程序。我要下载文件附件从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 ?

推荐答案

我是能够使下载和preVIEW按钮弹出在Android GMail中通过删除方案数据过滤器在我的意图(删除计划行并给它一试):

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属性将被忽略。该计划和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:

方案://主机:端口/路径 在路径preFIX pathPattern

因此​​,没有一个计划,所有这一切下降。发现上面之后,我尝试了明显的 - 使用*的计划,甚至试图*。无论是那些工作。我希望别人能建立过我的考验。但我相信这是与选择正确的方案。不幸的是,唯一的办法,我知道的是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的显示下载/ preVIEW按钮。事实上,这也将导致你的应用程序打开时.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.