Android 中发送电子邮件后的 Toast
很长一段时间以来,我一直在尝试在用户单击发送按钮并且电子邮件已发送后出现警报,例如吐司。我的代码似乎是正确的,但吐司没有出现。我一直在寻找正确的方法,但我被困住了。 任何帮助将不胜感激!
问候 安德斯
//我的代码
public class mailer extends Activity {
private Button clickBtn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
clickBtn = (Button) findViewById(R.id.button1);
//clickBtn.setText("Skicka info!");
clickBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String[] recipients = new String[]{"[email protected]","[email protected]"};
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Applikationsutveckling Android");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Jag vill veta mer om utbildningen!");
emailIntent.setType("text/plain");
startActivityForResult(Intent.createChooser(emailIntent, "Skicka e-post..."),1);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
Toast.makeText(mailer.this,
"Tack för din intresseanmälan!",
Toast.LENGTH_SHORT).show();
}
}
}
}
I've been trying for a long time to get an alert, like the toast, to come up after the user has clicked on send button, and the e-mail has been sent. My code seem to be correct, but the toast don't show up. I've been searching a lot to get it right, but I'm stuck.
Any help would be appreciated!
Regards
Anders
//My code
public class mailer extends Activity {
private Button clickBtn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
clickBtn = (Button) findViewById(R.id.button1);
//clickBtn.setText("Skicka info!");
clickBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String[] recipients = new String[]{"[email protected]","[email protected]"};
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Applikationsutveckling Android");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Jag vill veta mer om utbildningen!");
emailIntent.setType("text/plain");
startActivityForResult(Intent.createChooser(emailIntent, "Skicka e-post..."),1);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
Toast.makeText(mailer.this,
"Tack för din intresseanmälan!",
Toast.LENGTH_SHORT).show();
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
抱歉,您可能需要找到其他东西,但我不相信您能够完成这项工作。据我所知,默认的 Android 电子邮件程序(Gmail、Email)通常会在电子邮件实际传输之前返回,并且在任何情况下通常不会使用 onActivityResult 模式进行通信。
Sorry, you might need to find something else, but I don't believe you'll be able to make this work. As far as I can tell the default Android email programs (Gmail, Email) typically return prior to the actual transmission of the email, and in any case generally do not communicate using the onActivityResult pattern.
试试这个..
try this ..