显示电子邮件后吐司android系统中发送?(Show Toast after email send

2019-09-18 09:15发布

我使用下面的代码来发送邮件

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL, new String[] { "abc@yahoo.com" });
i.putExtra(Intent.EXTRA_CC, new String[] { bcc_string });
i.putExtra(Intent.EXTRA_SUBJECT, "Video Suggest");
i.putExtra(Intent.EXTRA_TEXT, url_link); 

try {
   startActivityForResult(Intent.createChooser(i, "Send Mail..."), 1);
} catch (android.content.ActivityNotFoundException ex) {
   Toast.makeText(AllVideos.this, "There are no email clients installed.", Toast.LENGTH_SHORT)
   .show();
}

在我上的活动结果我用下面的代码

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // System.out.println("inactivity");
    // Toast.makeText(AllVideos.this, "Mail Send", 10).show();

    System.out.println("inside activity result");

    if (requestCode == 1) {
        if (requestCode == 1 && resultCode == RESULT_OK) {
            Toast.makeText(this, "Mail sent.", Toast.LENGTH_SHORT).show();

        } else if (requestCode == 1 && resultCode == RESULT_CANCELED) {
            Toast.makeText(this, "Mail canceled.", Toast.LENGTH_SHORT)
                    .show();
        } else {
            Toast.makeText(this, "Plz try again.", Toast.LENGTH_SHORT)
                    .show();
        }
    }
}

但每次我发送或丢弃这个消息我收到“邮件取消”举杯。 请帮我把这个问题。

提前致谢。

Answer 1:

按照链接

你不能,这不是API的一部分。 它返回即使不发送它一旦按下发送按钮

ACTION_SEND没有任何输出,结果你总是得到RESULT_CANCELED默认值。

你也不能故意数据回来检查,因为它始终为空或者电子邮件发送或丢弃。



Answer 2:

试试这个方法。

 if (requestCode == 1) 
   {
        if (resultCode == RESULT_OK) 
        {
            Toast.makeText(this, "Mail sent.", Toast.LENGTH_SHORT).show();

        } 
        else if (resultCode == RESULT_CANCELED) 
        {
            Toast.makeText(this, "Mail canceled.", Toast.LENGTH_SHORT)
                    .show();
        } 
        else 
        {
            Toast.makeText(this, "Plz try again.", Toast.LENGTH_SHORT)
                    .show();
        }
  }


文章来源: Show Toast after email send in android?