我使用下面的代碼來發送郵件在Android中發送電子郵件後發送Toast?
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
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();
}
}
}
但每次我發送或丟棄這個消息我收到「郵件取消「敬酒。 請幫我把這個。
在此先感謝。
我沒想到onActivityResult一直在發送郵件 – Blundell
您將無法顯示,它不起作用。 –
@Blundell - onActivityResult正在工作,我可以發送郵件,但我只想在發送後顯示敬酒。 – Shrikant