I've fallen foul of this today too on my Note 2 and with a customer with a SG3. I did a bit of digging and discovered the following.
If I request the external storage device name - Environment.getExternalStorageDirectory().getName() (I use this as I'm targetting ver 7) - I get 'sdcard0', if I then add my filename and pass that to email or gmail then neither one will add the attachment. If I manually edit the zero off the end of 'sdcard0' and pass 'sdcard' + my filename then it all works just fine.
None of this seem to be a problem before JB or if I run this code under JB in the emulator which always returns 'sdcard'.
I'm not sure if there is different code that I am supposed to use or if this is an inconsistency in the way the os reports the path and the email systems use it. (I had thought that sdcard0 was supposed to point to the same place as sdcard - but something isn't working)
I may just patch my code to strip off the zero (which I know is ugly & dangerous). Unless anyone else has any bright ideas :)
Edit:
I have added my code below in case anyone else might find it useful.
// try and grab the log file
String logFile = File.separator + getResources().getString(R.string.app_name) + File.separator + "logs" + File.separator + Constants.SMS_FILE;
String extStorage = Environment.getExternalStorageDirectory().getName();
// The following is a kludge for the Samsung (and maybe more) JB devices that don't allow you to add a file with the SDCARD0 external storage
// link
File nf = new File(extStorage, logFile);
if (!nf.exists()) {
// OK we can't find the file - say so and see if we are hiding behind SDCARD0
Log.w(getLocalClassName() + ".shouldOverrideUrlLoading", "File: " + extStorage + logFile + " Doesn't exist - trying again");
if (extStorage.matches("(?i)SDCARD(?-i)[0-9]")) {
// OK we've got a SDCARDx scenario - let's see if the file exists without the x
String extStorageFix = extStorage.replaceFirst("(?i)SDCARD(?-i)[0-9]", extStorage.substring(0, 6)); // try it without the 0,1,2 etc
nf = new File(extStorageFix, logFile);
if (!nf.exists()) {
// OK we're in the pooh now - can't find the log file so just say so and try to exit without attaching it.
Log.w(getLocalClassName() + ".shouldOverrideUrlLoading", "File: " + extStorageFix + logFile + " Doesn't exist either - giving up");
Toast.makeText(
getApplicationContext(),
"Unable to attach Log file from\n" + extStorage + logFile + "\n" + extStorageFix + logFile
+ "\nPlease add it manually if possible", Toast.LENGTH_LONG).show();
} else {
// Hurrah we found it - remember we did so and carry on
extStorage = extStorageFix;
Log.w(getLocalClassName() + ".shouldOverrideUrlLoading", "Found logfile at: " + extStorage + logFile);
}
}
}
if (Debug.ON) {
Log.d(getLocalClassName() + ".shouldOverrideUrlLoading", "Filepath = " + "file://" + File.separator + extStorage + logFile);
}
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + File.separator + extStorage + logFile));**strong text**