CHollman82
CHollman82

Reputation: 616

Sending email with attachment from android app used to work, now does not, no idea what changed

I have a 2+ year old app that I just made some minor changes to and I seem to have broken the ability to send emails with file attachments from the app, which used to work... here is the code, it hasn't changed...

File path = new File(G.FilePath + "/" + ContextMenuFileName);
String subject = D.OTDRNAME + " OTDR Trace File: \"" + ContextMenuFileName + "\"";
String message = "This e-mail was sent from the " + D.APPNAME + " Android application.";
Uri URI = Uri.parse("file://" + path.getPath());

Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("application/octet-stream"); 
emailIntent.putExtra(Intent.EXTRA_TEXT, message);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_STREAM, URI);             
startActivity(Intent.createChooser(emailIntent, "Select E-Mail Application"));
return true;

When using the app it will ask me for the app to use to send the email (per the Intent.createChooser() call) and I choose gmail and then the gmail app starts up with the subject and body of the message filled in and with a symbol showing the file attachment... so the gmail app is showing the file attachment... yet no matter where I send the email to the attached file never shows up on the receiving end.

Here is a screenshot of the emailIntent details showing the URI string in use just before calling startActivity()

https://i.sstatic.net/h6daP.png

Upvotes: 0

Views: 176

Answers (1)

greenapps
greenapps

Reputation: 11224

The problem is that you serve your file from private intern memory unaccessable for other apps.

You could leave it there and make it 'world readable' but that is an old technic. Better serve the file with a FileProvider.

Upvotes: 0

Related Questions