Sending file via email from Cache directory
<p>I am trying to send file attached email from my App.</p>

<p>the file saved into external storage(SDCard) can successfully attatched, but the same file that is saved into temporary directory where i can get getCacheDir() method cannot be attached.</p>

<p>The only difference is to where the file i want to attatch is saved,
Is this because of an Android spec or limitation, or am i missing something?</p>

<p>Im using ACTION_SEND intent to send attatchment file via email</p>

<pre><code>//// getting file path to save
//[fail] -- no attatchment in email
//path = new StorageUtil().getCacheFilePath(this, "attatchment.html");
//[success] -- attatchment.html is on email
path = new StorageUtil().getExternalAppStoragePath(this, "attatchment.html");
/// start intent if file saving is successful
if (this.export(path)==true) {
    Intent i = new Intent();
    i.setAction(Intent.ACTION_SEND);
    i.setType("text/html"); 
    i.putExtra(Intent.EXTRA_SUBJECT, "a subject");
    i.putExtra(Intent.EXTRA_TEXT, "");
    File f = new File(path);
    i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
    startActivity(Intent.createChooser(i, "Send Email"));
}
</code></pre>

<p>getCacheFilePath() creates path from following code where fileName is the second argument of the method:</p>

<pre><code>File cacheDir = ctx.getCacheDir();
File cacheFile = new File(cacheDir, fileName);
return cacheFile.getPath(); //path
</code></pre>

<p>each path is as follows</p>

<pre><code>//cache dir (attachcment failed): 
/data/data/{PACKAGE_NAME}/cache/attachment.html

//external dir (attachment successed): 
/mnt/sdcard/Android/data/{PACKAGE_NAME}/files/attachment.html
</code></pre>

<p>File object from the cache dir canRead() and could obtain file length.
thanks!</p>

<p>== SOLVED ==</p>

<p>I found that the following error is on Logcat when sending Gmail:</p>

<pre><code>file:// attachment paths must point to file:///mnt/sdcard. Ignoring attachment file:///data/data/{PACKAGE_NAME}/cache/attachment.html"
</code></pre>

<p>so this should be a Android limitation. adding Intent.FLAG_GRANT_READ_URI_PERMISSION has no effect and other Activity like Dropbox results similar.</p>
