[英]How can I tell if my email has been sent?
I'm using the following code to send an email in my app. 我正在使用以下代码在我的应用中发送电子邮件。
public void sendEmail() {
emailSent = 1;
String to = toEmail.getText().toString();
String subject = getUser() + " - User Feedback";
String message = bodyTxt;
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);
email.setType("message/rfc822");
try {
startActivity(Intent.createChooser(email, "Send Email..."));
} catch (android.content.ActivityNotFoundException ex) {
String msg = ex.getMessage().toString();
emailSent = 2;
Toast.makeText(this, "There was a problem sending this email, please try again.", Toast.LENGTH_SHORT).show();
}
}
The email.setType() presents a screen offering options for which method to send the message including email. email.setType()显示一个屏幕,其中提供了用于选择发送电子邮件(包括电子邮件)的方法的选项。 This works fine if the user selects email as a copy of the email comes up and the user can then send it.
如果用户选择电子邮件作为电子邮件副本出现,然后用户可以发送它,则此方法很好。 However, if the user doesn't do anything and simply uses the back space it returns to the app and assumes the email has been sent.
但是,如果用户什么也不做,仅使用退格键,它将返回到应用程序并假定电子邮件已发送。 How can I test for the user not sending the email?
如何测试用户未发送电子邮件?
You could startActivityForResult()
and listen for a RESULT_OK
in onActivityResults
. 您可以
startActivityForResult()
并在onActivityResults
监听RESULT_OK
。 But there is no framework requirement that forces the email app to setResult appropriately. 但是,没有框架要求可以强制电子邮件应用适当地设置setResult 。 So your mileage may vary based on the email client app.
因此,您的里程可能会因电子邮件客户端应用程序而异。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.