很长时间以来,我一直在尝试在用户点击发送按钮并发送电子邮件之后出现一个警报,比如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[]{"donald@oo.se","laura@oo.se"};
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();
}
}
}
}
对不起,你可能需要找别的东西,但我不相信你能做到这一点。据我所知,默认的Android电子邮件程序(Gmail, email)通常在实际传输电子邮件之前返回,并且在任何情况下通常不使用onActivityResult模式进行通信。
try this .
if(requestCode==1 && resultCode==Activity.RESULT_OK)
{
Toast.makeText(Activity, "Mail sent.",
Toast.LENGTH_SHORT).show();
}
else if (requestCode==1 && resultCode==Activity.RESULT_CANCELED)
{
Toast.makeText(Activity, "Mail canceled.",
Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(Activity, "Plz try again.",
Toast.LENGTH_SHORT).show();
}