title: Android: How do I attach a temporary, generated image to an email?
body: <p>I have a programmatically generated image that I want to send as an attachment via the <code>ACTION_SEND</code> and <code>EXTRA_STREAM</code> method.</p>
  
  <p>But how do i do this?</p>
  
  <p>My first attempt (writing to my <code>context.getCacheDir()</code> based file path) appeared to work in the Gmail preview (no image preview, but attached file name and icon was visible), but the attachment never arrived on the recipient side. I guess this has something to do with permissions on the generated file, but how to avoid this? Do I need to set more permissive settings on these generated files (so that the Gmail activity can access)? Is that even possible for the app's cache folder?</p>
  
  <p>Is there another file location that would be more suitable to write my files to? I considered the downloads folder, but think it would be an awkward location for something that only needs to exist until it has been emailed.</p>
  
  <p>I have even tried encoding my image purely in a <code>data:image/png;base64,ABCD...</code> style URI. This, too, showed up in Gmail preview (attachment icon, but no file name), but did not result in a recipient-side attachment.</p>
  
  <p>Has anyone been able to attach a one-shot generated image to an email intent by any means? What options may I have overlooked?</p>