我正在尝试一个简单的电子邮件应用程序。我引用了这个链接 http://www.mkyong.com/android/how-to-send-email-in-android/
但我在模拟器和真实设备上收到错误“没有应用程序可以执行此操作”。如何克服此错误。也如上面发送按钮上的链接中所述,出现选择电子邮件客户端选项。如何获取这个?有人可以指导我吗?提前谢谢。我的代码是:
package com.example.androidsample4;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MakeComment extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.comment);
TextView tv1=(TextView)findViewById(R.id.textView1);
TextView tv2=(TextView)findViewById(R.id.textView2);
TextView tv3=(TextView)findViewById(R.id.textView3);
TextView tv4=(TextView)findViewById(R.id.textView4);
TextView tv5=(TextView)findViewById(R.id.textView5);
final EditText ed1=(EditText)findViewById(R.id.editText1);
EditText ed2=(EditText)findViewById(R.id.editText2);
final EditText ed3=(EditText)findViewById(R.id.editText3);
final EditText ed4=(EditText)findViewById(R.id.editText4);
ed3.setKeyListener(null);
Button b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//String to = ed3.getText().toString();
String name = ed1.getText().toString();
String message = ed4.getText().toString();
Intent email = new Intent(Intent.ACTION_SENDTO);
// email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});
//email.putExtra(Intent.EXTRA_CC, new String[]{ to});
//email.putExtra(Intent.EXTRA_BCC, new String[]{to});
email.putExtra(Intent.EXTRA_SUBJECT, name);
email.putExtra(Intent.EXTRA_TEXT, message);
//need this to prompts email client only
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
}
});
}
}