public class AndroidEmailActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText edittextEmailAddress = (EditText) findViewById(R.id.email_address);
final EditText edittextEmailSubject = (EditText) findViewById(R.id.email_subject);
final EditText edittextEmailText = (EditText) findViewById(R.id.email_text);
Button buttonSendEmail_intent = (Button) findViewById(R.id.sendemail_intent);
buttonSendEmail_intent.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String emailAddress = edittextEmailAddress.getText().toString();
String emailSubject = edittextEmailSubject.getText().toString();
String emailText = edittextEmailText.getText().toString();
String emailAddressList[] = { emailAddress };
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, emailAddressList);
intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
intent.putExtra(Intent.EXTRA_TEXT, emailText);
startActivity(Intent.createChooser(intent,
"Choice App t send email:"));
}
});
}
}
这是我的代码。我没有收到任何电子邮件。我需要通过这种意图方法发送电子邮件。我能否实现这一点?我哪里出错了?请提出一些建议。
单击“发送电子邮件”按钮时出现错误,因为“没有应用程序可以执行此操作。”
答案 0 :(得分:1)
这是我发送电子邮件的代码:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, activity.getString(R.string.share_email_subject));
sendIntent.setType("message/rfc822");
activity.startActivity(Intent.createChooser(sendIntent, "Choose Email Client"));
尝试删除普通/文本类型?
答案 1 :(得分:0)
使用原始设备而不是虚拟设备是一种好习惯。我建议你在真实设备上试试这个代码块。
Intent sendEmail= new Intent(Intent.ACTION_SEND);
sendEmail.setType("plain/text");
startActivity(Intent.createChooser(sendEmail, "Email:"));
如果您想了解有关使用Intent的电子邮件的更多信息,请参阅此帖子: http://androidtutforbeginner.blogspot.com/2012/03/send-email-with-intent-in-android.html