强制的Andr​​oid挑选的电子邮件发送程序 [英] Force android to pick an app for email sending

查看:105
本文介绍了强制的Andr​​oid挑选的电子邮件发送程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现从我的应用程序发送电子邮件。

我用这quesion上SO 为指导,以实现这一目标,需要注意的是在回答有人说要用的setType(信息/ RFC822); ,因为它过滤掉所有其他的电子邮件客户端,听 ACTION_SEND 意图。

我的问题是,我的Galaxy Tab 10.1仍然有两个应用程序,听的意图,所以弹出仍然打开问我想用什么电子邮件客户端。 (Gmail应用或默认的电子邮件应用程序)。我无法卸载一个,这样的列表将不会弹出,但我并不想要么。

有没有办法迫使Android的只使用列表中的瞬间第一个?因此,用户可以跳过弹出的对话框?

下面是我目前的code:

 意向书I =新意图(Intent.ACTION_SEND);
i.setType(信息/ RFC822);i.putExtra(Intent.EXTRA_SUBJECT,context.getString(R.string.notes_from_pf));
i.putExtra(Intent.EXTRA_TEXT,context.getString(R.string.mail_message));
尝试{
    startActivity(Intent.createChooser(我,发送邮件...));
}赶上(android.content.ActivityNotFoundException前){
    Toast.makeText(背景下,有没有安装的电子邮件客户端。Toast.LENGTH_SHORT).show();
}


解决方案

查询程序,获取的这些注册以给行动和选择一个,创建一个意图的应用程序列表,设置类的名字,开始你的意图和你做

I implemented sending emails from my application.

I used this quesion on SO as a guide to achieve this, note that in the answers someone said to use setType("message/rfc822"); because it filters out all other email client that listen to the ACTION_SEND intent.

My problem is that my galaxy tab 10.1 still has two application that listen to the intent, so a popup still opens asking me what email client I want to use. (The gMail app or the default eMail app). I can't uninstall one so the list won't popup, but I don't want to either.

Is there a way to force android to just use the first one in the list instantly? So the user can skip the popup dialog?

Here is my current code:

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");

i.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.notes_from_pf));
i.putExtra(Intent.EXTRA_TEXT  , context.getString(R.string.mail_message));
try {
    startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(context, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}

解决方案

query applications, get a list of applications which are register to send action and choose one, create an intent, set class name and start your intent and you're done

这篇关于强制的Andr​​oid挑选的电子邮件发送程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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