点击按钮,从Android应用程序发送电子邮件

我需要为用户提供function,用户可以通过发送电子邮件来共享某些数据。 我使用下面的代码。

Intent email = new Intent(android.content.Intent.ACTION_SENDTO); email.setType("message/rfc822"); email.putExtra(Intent.EXTRA_EMAIL, new String[] { to }); email.putExtra(Intent.EXTRA_SUBJECT, subject); email.putExtra(Intent.EXTRA_TEXT, message); startActivity(Intent.createChooser(email,"Choose an Email client :")); 

这显示了Email,gmail,Skype和蓝牙发送供用户选择。 我不希望用户显示Skype,在此列表中通过蓝牙发送。 我需要做什么 ? 我的手机中有WhatsApp,它做同样的事情,但没有在列表中显示电子邮件,蓝牙(设置 – >帮助 – >联系人 – > …)。只显示列表中的电子邮件和Gmail。 我需要做同样的事情。

尝试这个:

 Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( "mailto","email@email.com", null)); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_TEXT, message); startActivity(Intent.createChooser(intent, "Choose an Email client :")); 

如果您没有特定的收件人 – 请执行以下操作:

 Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( "mailto", "", null)); 

使用此方法只通过gmail共享你需要调用的jus

 startActivity(getSendEmailIntent(context, email,subject, body)); public Intent getSendEmailIntent(Context context, String email, String subject, String body) { Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); try { // Explicitly only use Gmail to send emailIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail"); emailIntent.setType("text/html"); // Add the recipients if (email != null) emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { email }); if (subject != null) emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); if (body != null) emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body)); // Add the attachment by specifying a reference to our custom // ContentProvider // and the specific file of interest // emailIntent.putExtra( // Intent.EXTRA_STREAM, // Uri.parse("content://" + CachedFileProvider.AUTHORITY + "/" // + fileName)); return emailIntent; // myContext.startActivity(emailIntent); } catch (Exception e) { emailIntent.setType("text/html"); // Add the recipients if (email != null) emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { email }); if (subject != null) emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); if (body != null) emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body)); // myContext.startActivity(Intent.createChooser(emailIntent, // "Share Via")); return emailIntent; } }