我有疑问。我去了一个电子邮件应用程序但是当我按下发送按钮时,我必须至少安装一个电子邮件应用程序。代码:
Java文件:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
final EditText adress = (EditText) findViewById(R.id.adress);
final EditText subject = (EditText) findViewById(R.id.subject);
final EditText message = (EditText) findViewById(R.id.message);
ImageButton send = (ImageButton) findViewById(R.id.send);
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , adress.getText().toString());
i.putExtra(Intent.EXTRA_SUBJECT, subject.getText().toString());
i.putExtra(Intent.EXTRA_TEXT , message.getText().toString());
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("Mail");
builder.setMessage("Mail send sucessfully.");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(MyActivity.this,"Finish.",Toast.LENGTH_SHORT);
adress.setText("");
subject.setText("");
message.setText("");
}
});
}
});
}
请帮助我。
答案 0 :(得分:0)
如果用户未在手机上安装电子邮件应用程序,您可以将用户带到PlayStore
并请求他下载自己选择的电子邮件应用程序(或您推荐的应用程序)。
另一个选择是拥有自己的SMTP服务器,您可以使用它来发送电子邮件。