Android的 - 如何直接打开电子邮件客户端客户端、电子邮件、直接、Android

2023-09-04 05:24:35 作者:浮殇年華

我想打开,而不是显示选项的默认电子邮件客户端。我试过,但我没有得到,请谁能帮助我。

I want to open the default email client instead of showing the options. I tried but i am not getting please can anyone help me.

我用下面的code:

  final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

        emailIntent.setType("text/html");
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My Allergy Journal");       
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("<small>"+sb.toString()+"</small>"));                                 
        startActivity(Intent.createChooser(emailIntent, "Email:"));   

这是显示的选项

但是我想直接打开,然后默认邮件客户端。

推荐答案

您可以用下面的code打开任何意图你想如Gmail中,脸谱,因为在我的$用在类型的电子邮件etc..Simple C $ C通过了Gmail的,如果你想打开Gmail时,通过变脸如果u想要打开Facebook的

You can used the following code to open whatever intent you want eg gmail, facebook, email etc..Simple in the type as used in my code pass "gmail" if you want to open gmail, pass "face" if u want to open facebook

Intent intent = new Intent(android.content.Intent.ACTION_SEND); 
intent.setType("text/html");
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(intent, 0);

if (!resInfo.isEmpty())
{
    for (ResolveInfo info : resInfo) 
    {
    if (info.activityInfo.packageName.toLowerCase().contains(type) || info.activityInfo.name.toLowerCase().contains(type)) 
    {
            intent.putExtra(android.content.Intent.EXTRA_TEXT, htmlBody);
            intent.setPackage(info.activityInfo.packageName);   
            startActivity(Intent.createChooser(intent, getResources().getString(R.string.share_send_text)));
        }
}