【问题标题】:Email Intent issue. Cannot select an email option电子邮件意图问题。无法选择电子邮件选项
【发布时间】:2013-02-06 00:36:47
【问题描述】:

更新:

管理对 gmail 的加载进行排序。

现在我无法在加载意图时设置 gmail 的“收件人”、“主题”和“消息”字段。

显示我的电子邮件布局的屏幕截图:

显示加载的 gmail 意图的屏幕截图。但没有从传递的详细信息中设置字段。

代码:

@Override
public void onClick(View sendEmailClick) {


    Intent sendEmailIntent = new Intent(Intent.ACTION_SEND); 
    sendEmailIntent.setType("plain/text");
       sendEmailIntent.putExtra(Intent.EXTRA_EMAIL, emailAdd);  
       sendEmailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSub); 
       sendEmailIntent.putExtra(Intent.EXTRA_TEXT, emailMess); 
       startActivity(Intent.createChooser(sendEmailIntent, "Send email"));

       //startActivity(Intent.createChooser(sendEmailIntent, "Send email..."));
}

【问题讨论】:

  • 使用intent.setType("text/plain");

标签: java android android-intent


【解决方案1】:

如果默认电子邮件客户端没有帐户,则不应注册Intent.ACTION_SEND。确保您已将帐户添加到应用程序并尝试再次发送您的电子邮件。如前所述,使用 "text/plain" 作为类型。

From what I can find on short notice:

<activity
            android:name=".activity.MessageCompose"
            android:label="@string/compose_title"
            android:enabled="false"
            android:theme="@android:style/Theme.Holo.Light"
            >

compose Activity 默认不开启,添加账号后应该开启。

【讨论】:

  • 非常感谢您的回复。我已经添加了我的 gmail 帐户,现在当我单击发送按钮时,onclick 方法会启动意图。我现在唯一的问题是我似乎无法使用传递的意图详细信息设置 Gmail 的“收件人”“主题”和“消息”字段吗?我将更新我的问题以显示这一点。
【解决方案2】:

您也可以在没有外部应用程序的情况下发送电子邮件:

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

String[] recipients = new String[]{"my@email.com", "",};

emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);

emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test");

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is email's message");

emailIntent.setType("text/plain");

startActivity(Intent.createChooser(emailIntent, "Send mail..."));

finish();

【讨论】:

  • 感谢您的回复。您的意思是说我不需要选择电子邮件应用程序来发送我的电子邮件吗?我已经尝试过您的 startActivity 并且遇到了同样的问题。我不使用字符串数组是否需要这种方法才能工作?我只是用我的edittext值设置我的'.EXTRA_EMAIL'。
  • 是的,您无需申请即可发送申请。您可以声明您的 edittext 并获取文本 String s = et.getText().toString(); 。现在你可以... EXTRA_TEXT, s);
【解决方案3】:
try {
    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{recipient});
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
    emailIntent.setType("plain/text");
    startActivity(Intent.createChooser(emailIntent, "Send email"));
} catch (ActivityNotFoundException e) {
    Log.i("app name", "Unable to send email");
}

【讨论】:

    【解决方案4】:

    设法让第二部分得到这样的排序。您需要将其作为字符串数组传递给 Gmail,而不仅仅是纯字符串。希望这将在未来解决其他人的问题!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-12
      • 2013-02-21
      • 2010-12-20
      • 2022-01-06
      • 2011-04-28
      • 2019-06-23
      • 2014-04-06
      相关资源
      最近更新 更多