从主题和密送的Android应用程序问题发送电子邮件

时间:2013-08-22 08:44:22

标签: android

你好我试图从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..."));
    }
});

3 个答案:

答案 0 :(得分: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;

答案 1 :(得分: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..."));
    }
});

请询问您是否理解

答案 2 :(得分: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));
        }