【问题标题】:Send information to email [duplicate]将信息发送到电子邮件 [重复]
【发布时间】:2016-01-08 22:23:48
【问题描述】:

我有一个 Activity,它有两个 TextField,用户可以在其中输入一些文本。

它们下面有一个按钮,我要提交信息输入两个TextFields。无论是电子邮件还是消息。

有没有办法让活动基本上向我提交用户信息?

【问题讨论】:

  • 您基本上需要一个带有EXTRA_EMAILEXTRA_SUBJECTEXTRA_TEXT 额外内容的 Intent。

标签: java android android-activity


【解决方案1】:

您需要使用 Intent 打开“撰写新电子邮件”并填写所需数据。

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL  , new String[]{emailAddressEditText.getText().toString()});
intent.putExtra(Intent.EXTRA_SUBJECT, emailSubjectEditText.getText().toString());
intent.putExtra(Intent.EXTRA_TEXT   , emailBodyEditText.getText().toString());
try {
    startActivity(Intent.createChooser(intent, "Leave feedback..."));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(MyActivity.this, "No email clients installed.", Toast.LENGTH_SHORT).show();
}

【讨论】:

    【解决方案2】:

    1.使用意图

    2.使用.setType("message/rfc822")

    buttonSend = (Button) findViewById(R.id.buttonSend);
    textTo = (EditText) findViewById(R.id.editTextTo);
     textSubject = (EditText) findViewById(R.id.editTextSubject);
     textMessage = (EditText) findViewById(R.id.editTextMessage);
    
     buttonSend.setOnClickListener(new OnClickListener() {
    
     @Override
     public void onClick(View v) {
    
     String to = textTo.getText().toString();
     String subject = textSubject.getText().toString();
     String message = textMessage.getText().toString();
    
         Intent email = new Intent(Intent.ACTION_SEND);
         email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});
         email.putExtra(Intent.EXTRA_SUBJECT, subject);
         email.putExtra(Intent.EXTRA_TEXT, message);
    
         email.setType("message/rfc822");
    
     startActivity(Intent.createChooser(email, "Choose an Email client :"));
    }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-02
      • 2017-10-28
      • 1970-01-01
      • 2022-01-17
      • 2014-10-24
      • 1970-01-01
      相关资源
      最近更新 更多