如何通过意图打开电子邮件程序(但只有一个电子邮件程序) [英] How to open Email program via Intents (but only an Email program)

查看:192
本文介绍了如何通过意图打开电子邮件程序(但只有一个电子邮件程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置我的应用程序的一部分,允许用户发送快速电子邮件给其他用户。这不是很难进行设置:

I want to setup a part of my application that allows users to send a quick email to another user. It's not very hard to set this up:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
Intent mailer = Intent.createChooser(intent, null);
startActivity(mailer);

然而,问题是,ACTION_SEND被接受,不仅仅是电子邮件程序 - 例如,我的手机上的Facebook应用程序,微博,reddit的是有趣的,甚至是蓝牙拿出来发送这个消息作为可行的替代方案。该消息完全是太长,其中的一些(尤其是微博)。

However, the problem is that the ACTION_SEND is accepted by more than just email programs - for example, on my phone the Facebook app, Twitter, reddit is fun, and even Bluetooth come up as viable alternatives for sending this message. The message is entirely too long for some of these (especially Twitter).

有没有一种方法来选择器限制,以支持长信息(如电子邮件)只是应用程序?或者是有没有办法适当地检测到用户选择的应用程序,并调整消息?

Is there a way to limit the chooser to just applications that support long messages (such as email)? Or is there a way to detect the app that the user has chosen and adjust the message appropriately?

推荐答案

更​​改MIME类型就是答案,这就是我做我的应用程序更改相同的行为。我用 intent.setType(信息/ RFC822);

Changing the MIME type is the answer, this is what I did in my app to change the same behavior. I used intent.setType("message/rfc822");

这篇关于如何通过意图打开电子邮件程序(但只有一个电子邮件程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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