Android: problem sending email with attachment from my application
<p>My application allows users to create and modify files.  I would like them to be able to send a file as an email attachment.  So, I need to first create and write to a temporary file, which I then attach to the email.  And then I would like to delete the temporary file when the email program finishes.  Unfortunately, the gmail app responds with a result code as soon as the user clicks "send"; and if I delete the file as soon as the result code is received, no attachment is sent. </p>

<p>Its possible that something else is going wrong and the attachment is not sent for a different reason, but I'm pretty sure my assessment is correct because the below code works properly if I comment out the <code>mEmailTmpFile.delete()</code> call.  It also works fine if I do something very undesirable like <code>Thread.sleep(4000)</code> immediately prior to <code>mEmailTmpFile.delete()</code>.  </p>

<p>Is there anyway to be notified when the email is done sending?  Or any other suggestions for how I should work around this?</p>

<pre><code>//send an email...

File externalStorage = Environment.getExternalStorageDirectory();
String sdcardPath = externalStorage.getAbsolutePath();
mEmailTmpFile = new File(sdcardPath + "/" +  name );

//do some other to ensure unqiueness and then write to the file...

//all done writing, send email

Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("application/zip");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, name);
sendIntent.putExtra(Intent.EXTRA_TEXT, "File attached.");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ mEmailTmpFile.getPath()));
startActivityForResult(Intent.createChooser(sendIntent, "Email"), REQUESTCODE_EMAIL);

public synchronized void onActivityResult(int reqCode, int resultCode, Intent data)
{
   if (reqCode == REQUESTCODE_EMAIL)
   {
    mEmailTmpFile.delete();
    }
}
</code></pre>
