这是代码,除了没有应用程序可以执行此操作“error..请告诉我代码中的错误是什么。
public void sends(View button) {
// Do click handling here
final EditText date = (EditText) findViewById(R.id.editText1);
String da = date.getText().toString();
final EditText phone = (EditText) findViewById(R.id.editText2);
String ph = phone.getText().toString();
final EditText nameplate = (EditText) findViewById(R.id.editText3);
String np = nameplate.getText().toString();
final EditText issue = (EditText) findViewById(R.id.editText4);
String i = issue.getText().toString();
StringBuilder s= new StringBuilder(100);
s.append(da);
s.append(". ");
s.append(ph);
s.append(". ");
s.append(np);
s.append(". ");
s.append(i);
String st=s.toString();
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
//emailIntent.setType("plain/text");
//startActivity(emailIntent);
startActivity(Intent.createChooser(emailIntent, "Send your email in:"));
Intent emailIntentt= new Intent(android.content.Intent.ACTION_SEND);
String aEmailList[] = { "[email protected]" };
emailIntentt.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
//emailIntentt.putExtra(android.content.Intent.EXTRA_CC, aEmailCCList);
//emailIntentt.putExtra(android.content.Intent.EXTRA_BCC, aEmailBCCList);
emailIntentt.putExtra(android.content.Intent.EXTRA_SUBJECT, "Feedback");
emailIntentt.setType("message/rfc822");
emailIntentt.putExtra(android.content.Intent.EXTRA_TEXT, st);
startActivityForResult(emailIntentt, REQUEST_SEND_MAIL);
}
public static final int REQUEST_SEND_MAIL = 1;
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_SEND_MAIL:
// When the request to send mail returns
if (resultCode == Activity.RESULT_OK) {
Toast.makeText(this, "message successfully sent", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "sorry", Toast.LENGTH_SHORT).show();
}
}}
最佳答案
你有startActivity()
和startActivityForResult
!!!!你需要一个。这就是为什么第一个意图被激发,而没有应用程序来捕捉它。
试试这个:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String aEmailList[] = { "[email protected]" };
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Feedback");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, st);
startActivityForResult(emailIntent, REQUEST_SEND_MAIL);
关于android - 发送电子邮件时出现错误“没有应用程序可以执行此操作”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11703114/