首先我有一个editText字段,它记录用户注释,我有一个功能按钮,从我的应用程序打开一个外部电子邮件应用程序。我想知道如何在电子邮件应用程序打开时为用户填写电子邮件的消息(来自editText字段)。 我提供了以下相关部分的代码片段。 这是我的onCreate方法:
public class TakeNotes extends Activity implements View.OnClickListener {
EditText tv;
Button btnSave;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.take_notes);
tv = (EditText) findViewById(R.id.txtInput);
btnSave= (Button) findViewById(R.id.save);
btnSave.setOnClickListener(this);
这是我的OnClickListener:
public void onClick(View v) {
switch (v.getId()) {
//some other code for a different function
case R.id.email:
Intent emailIntent = new
Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Email Message");
startActivity(emailIntent);
startActivity(Intent.createChooser(emailIntent, "Send your email
in:"));
我认为这与这一行有关,但我不确定我需要添加什么:
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Email Message");
感谢任何帮助
答案 0 :(得分:0)
尝试这样做:
EditText text;
Button btnSave;
String emailstring;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_checking_intent);
text = (EditText) findViewById(R.id.email);
btnSave = (Button) findViewById(R.id.button);
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
emailstring = text.getText().toString();
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of your email");
i.putExtra(Intent.EXTRA_TEXT , emailstring);
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(CheckingIntent.this, "There are no email app installed.", Toast.LENGTH_SHORT).show();
}
}
});
}