我正在尝试构建一个简单的Android应用程序,使用android intent属性发送电子邮件。我使用按钮的onClicklistener来触发调用电子邮件客户端的intent函数但是由于某种原因不能正常工作。我还看到当我点击按钮是代码底部的Toast消息。没有提示要求电子邮件客户端或任何东西。
buttonSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if ( mu.isInternetAvailable(SendMessage.this) ==true)
{
Log.i("START ONCLICK","");
String to = emailid.getText().toString();
String subject = textSubject.getText().toString();
String driverId1=driverid.getText().toString();
String message = textMessage.getText().toString();
SharedPreferences spmail = SendMessage.this.getSharedPreferences("email", MODE_WORLD_READABLE);
driver_mail=spmail.getString("email","");
Log.i("SEND MAIL id is","DRIVERID "+driver_mail);
Intent email = new Intent(Intent.ACTION_SENDTO);
//need this to prompts email client only
email.setType("message/rfc822");
email.setData(Uri.parse("mailto:"));
String[] to1={"info@ZapaTaxi.com"};
email.putExtra(Intent.EXTRA_EMAIL, to1);
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(email, "Choose an Email client :"));
Toast.makeText(SendMessage.this, "E-mail succesfully sent!!!!!", Toast.LENGTH_SHORT).show();
Intent it1=new Intent(SendMessage.this,Home.class);
startActivity(it1);
}
}
答案 0 :(得分:0)
你必须将此代码放在其他地方:
Intent it1=new Intent(SendMessage.this,Home.class);
startActivity(it1);