how can we use startActivityforResult() for Email intent?

后端 未结 3 1324
一整个雨季
一整个雨季 2020-11-29 12:21

I am using intent for send email with attachment,it is work fine,i want to get this email intent result,i already used startActivityforResult(),but i can\'t get

3条回答
  •  我在风中等你
    2020-11-29 12:40

    You sort of can, but it's ugly and inelegant. I'll work on smoothing this out. The main problem: After the email is sent you end up at a black screen with nothing but your app title at the top.

    I'll do a 'hit enter to continue' or something if I have to.

    Anyway: First snippet from main class writes the report to sdcard, then calls the activity that will send email.

    WriteReportToStorage();
    
    Intent Emailreport = new Intent(bvsactivity.this, Emailreport.class);
    startActivityForResult(Emailreport,emailreport_ran);
    

    Next, over in the emailreport class we do the standard email+attachment sending code:

    public class Emailreport extends Activity {
    
    @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
    final Intent email = new Intent(android.content.Intent.ACTION_SEND);
            email.setType("text/html
    
    ");
                email.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject");
                email.putExtra(android.content.Intent.EXTRA_TEXT, "body");
                email.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("file:/" +      Environment.getExternalStorageDirectory() + "//Report.html"));
                startActivity(Intent.createChooser(email, "Email:"));
            }
    

    Lastly, back in your 'main' class, the onactivityresult that deletes the sdcard file:

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            // Actions based on which menu item we chose.
            if (requestCode == emailreport_ran) {boolean deleted = reportfile.delete(); emailreport_ran = 1;}
            }
     }
    

提交回复
热议问题