电子邮件附件的意图过滤器
我想使用我的应用程序打开电子邮件中的音频附件。目前我的意图过滤器是这样的:
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="audio/wav" />
<data android:scheme="http" android:host="*" android:pathPattern=".*\\.wav"/>
<data android:scheme="https" android:host="*" android:pathPattern=".*\\.wav"/>
<data android:scheme="content" android:host="*" android:pathPattern=".*\\.wav"/>
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.wav"/>
</intent-filter>
这适用于我想要的一切,除了电子邮件附件。目前,如果我收到一个 wav 文件,我唯一能做的就是预览它,然后用 Winamp 打开它(很明显,第三方应用程序有办法进入)。我找不到我应该添加什么来做到这一点,有人有任何想法吗?
编辑
以下是 LogCat 对此事的看法。当我单击预览时,我得到
01-10 19:28:52.691: INFO/ActivityManager(109): Starting: Intent { dat=content://gmail-ls/messages/xxxxxxx%40gmail.com/439/attachments/0.1/BEST/false cmp=com.google.android.gm/.ViewAttachmentActivity } from pid 19483
奇怪的是 Winamp 自动打开,并且没有设置为默认值。我别无选择...
I want to open audio attachments in emails with my app. Currently my intent filter is like so:
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="audio/wav" />
<data android:scheme="http" android:host="*" android:pathPattern=".*\\.wav"/>
<data android:scheme="https" android:host="*" android:pathPattern=".*\\.wav"/>
<data android:scheme="content" android:host="*" android:pathPattern=".*\\.wav"/>
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.wav"/>
</intent-filter>
This works for everything I want it to except for email attachments. Currently if I'm sent a wav file, the only thing I can do is preview it, and that opens with Winamp (so clearly 3rd party apps have a way in). I can't find what I should be adding to do this though, does anyone have any idea?
Edit
Here's what LogCat has to say on the matter. When I click Preview I get
01-10 19:28:52.691: INFO/ActivityManager(109): Starting: Intent { dat=content://gmail-ls/messages/xxxxxxx%40gmail.com/439/attachments/0.1/BEST/false cmp=com.google.android.gm/.ViewAttachmentActivity } from pid 19483
What's bizarre is that Winamp automatically opens, and is not set as default. I'm given no choice...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
audio/wav
替换为audio/*
可以使其工作,但这显然是不受欢迎的行为。Replacing
audio/wav
withaudio/*
makes it work, however this is obviously undesirable behaviour.电子邮件客户端似乎以任意方式选择附件的 mimetypes,因此打开它们的意图过滤器必须考虑所有可能性。搜索互联网有助于找到所有可能的类型,如果没有像
audio/*
这样的通配符,则应该为每个类型添加一个过滤器所需(如OP所说)。
无论如何,建议将按 mimetype 过滤作为首选,而不是按文件扩展名过滤(请参阅 此线程在 android-dev ml 上)。
(感谢弗莱德利)
email clients seem to choose mimetypes for attachments in an arbitrary way, so intent filters to open them must contemplate all possibilities. searching the internet helps to find all the possible types and one should add a
<data/>
filter for each of them, if a wildcard likeaudio/*
is not desired (as OP says).anyway, filtering by mimetype is suggested as a first choice other than filtering by filename extension (see this thread on android-dev ml).
(thanks fredley)