2

您好,我正在尝试从 android 应用程序发送电子邮件,下面的代码工作正常,因为它正在打开手机上配置的电子邮件应用程序,但问题是它没有接受主题和密件抄送任何想法

send.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("plain/text");
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ address.getText().toString()});
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText());
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailBody.getText());
        emailIntent.putExtra(android.content.Intent.EXTRA_BCC, CC.getText());
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));
    }
});
4

3 回答 3

1

尝试

send.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("plain/text");
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ address.getText().toString()});
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText().toString());
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailBody.getText().toString());
        emailIntent.putExtra(android.content.Intent.EXTRA_BCC, CC.getText().toString());
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));
    }
});

EditText.getText() 返回一个可编辑的内容,您需要通过应用 toString() 将其更改为 String;

于 2013-08-22T08:48:05.130 回答
1

正如您在获取地址中看到的那样,您通过.getText(); 获得了文本;然后您将其设为其他用途的字符串,因为它是来自editText的可编辑文本。但是在其他EditTextss中,您忘记添加.toString(); 因此您可以将其用作电子邮件中的字符串。

试试这个:

send.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {

        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("plain/text");

        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ address.getText().toString()});
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText().toString());
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailBody.getText().toString());
        emailIntent.putExtra(android.content.Intent.EXTRA_BCC, CC.getText().toString());

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

请问您是否不明白

于 2013-08-22T09:42:01.043 回答
0

将工作 100%

String[] to = value.toString().split(",");
        Intent i = new Intent(Intent.ACTION_SEND);
        i.setType("text/html");
        i.putExtra(Intent.EXTRA_EMAIL, to);
        i.putExtra(Intent.EXTRA_BCC, "array of bcc like to");
        i.putExtra(Intent.EXTRA_SUBJECT, String.format(getString(R.string.share_email_subject), IN_SHARE_CAPTION));
        i.putExtra(
                Intent.EXTRA_TEXT,
                Html.fromHtml(IjoomerUtilities.prepareEmailBody(message == null ? "" : message, getSmartApplication().readSharedPreferences().getString(SP_USERNAME, "") + " " + getString(R.string.saw_this_story_on_the) + " "
                        + getString(R.string.app_name) + " " + getString(R.string.thought_you_should_see_it), IN_SHARE_CAPTION, IN_SHARE_DESCRIPTION, IN_SHARE_SHARELINK, getString(R.string.try_ijoomeradvance), getString(R.string.site_url))));
        try {
            startActivity(Intent.createChooser(i, "Send mail..."));
            finish();
        } catch (android.content.ActivityNotFoundException ex) {
            ting(getString(R.string.share_email_no_client));
        }
于 2013-08-22T08:54:01.007 回答