[英]android Action_send intent how to know once an email has been sent to close the current activity?
我有一個action_send意圖,該意圖允許用戶發送電子郵件,但是當他們完成操作后,我希望將他們返回到與發送電子郵件時不同的活動。 我的意圖代碼如下:
public void sendEmail(){
String path = Environment.getExternalStorageDirectory().toString() + "/" + "screenshots/";
String target_filename = "CheeseNav.jpg";
File externalFile = new File(path, target_filename);
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL, new String[]{""});
i.putExtra(Intent.EXTRA_SUBJECT, "Email sent from android app");
i.putExtra(Intent.EXTRA_TEXT, "");
Uri sendUri = Uri.fromFile(externalFile);
i.putExtra(Intent.EXTRA_STREAM, sendUri);
try{
startActivity(Intent.createChooser(i, "Send mail..."));
} catch(android.content.ActivityNotFoundException ex){
Toast.makeText(ScreenViewer.this, "There are no email clients installed.",
Toast.LENGTH_SHORT).show();
}
}
如果要返回到某個活動之前,必須先發送帶有標志的意圖來清除活動的頂部,然后再發送電子郵件。 您可以使用Intent.FLAG_ACTIVITY_CLEAR_TOP
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.