我如何检测是否在Android设备上配置电子邮件客户端? [英] How do I detect if an email client is configured on an Android device?

查看:162
本文介绍了我如何检测是否在Android设备上配置电子邮件客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何检测是否在Android设备上配置电子邮件客户端?如果没有配置电子邮件帐户的Andr​​oid会将其作为短信(我用android.content.Intent.ACTION_SEND)。我想提示没有电子邮件客户端配置的用户。

How do I detect if an email client is configured on an Android device? If no email account is configured Android treats it as text message (I use android.content.Intent.ACTION_SEND). I want to prompt the user that no email client is configured.

推荐答案

,考虑通过包裹ACTION_SEND意图在选配<一href=\"http://developer.android.com/reference/android/content/Intent.html#createChooser%28android.content.Intent,%20java.lang.CharSequence%29\"相对=nofollow> createChooser()。 createChooser()将返回用户选取的​​意图。如果用户没有选择一个有效的电子邮件客户端,你或许可以弹出一个错误信息,或与设置屏幕来声明一个有效的电子邮件客户端提供给用户。

Instead of prompting the user that no email client is configured, consider wrapping the ACTION_SEND intent in a chooser via createChooser(). createChooser() will return the intent that the user picked. If the user did not pick a valid email client, you can perhaps pop up an error message or provide the user with the settings screen to declare a valid email client.

请注意,这是不可能的,以确定一个发送应用程序是否是一个有效的电子邮件应用程序中,只是是否是用于发送的应用程序。这就是为什么选择器应使用,从而使用户将认识到,它们不具有电子邮件客户端设置一个。另外请注意,这是极为罕见的用户没有电子邮件客户端,因为它们必须至少与他们的谷歌帐户注册,当他们开始他们的电话(给他们访问Gmail)。

Note that it is not possible to determine whether a sending application is a valid "email" application, just whether it is an application for sending. This is why the chooser should be used, so that the user will be the one to realize that they do not have an email client set up. Also note that it is extremely rare for a user to have no email client, as they must at least register with their google account when they start their phone (giving them access to gmail).

这是一个有一个选择器发送邮件的例子:

Here's an example for sending an email with a chooser:

sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("application/octet-stream");
sendIntent.putExtra(Intent.EXTRA_EMAIL,new String[] {"myuser@gmail.com"});
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Email Subject");
sendIntent.putExtra(Intent.EXTRA_TEXT, "Body text of email message");
startActivity(Intent.createChooser(sendIntent, "Send Mail"));

这篇关于我如何检测是否在Android设备上配置电子邮件客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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