Android Intent to send email with the app

Possible duplicate:
Email from internal storage

The letter is received by the recipient, but without attachment. Here is the code, does any expert know where I made a mistake?

Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"email@example.com"}); intent.putExtra(Intent.EXTRA_SUBJECT, "subject here"); intent.putExtra(Intent.EXTRA_TEXT, "body text"); File root = Environment.getExternalStorageDirectory(); File file = new File(root, xmlFilename); if (!file.exists() || !file.canRead()) { Toast.makeText(this, "Attachment Error", Toast.LENGTH_SHORT).show(); finish(); return; } Uri uri = Uri.parse("file://" + file); intent.putExtra(Intent.EXTRA_STREAM, uri); startActivity(Intent.createChooser(intent, "Send email...")); 

I do not receive a message with toasts. Thank.

+60
java android android-intent attachment
May 20 '11 at 22:15
source share
2 answers

Try:

 Uri.fromFile(file); 

instead:

 Uri.parse("file://" + file); 

Also, try text/xml for your MIME type, considering it to be an XML file that offers your variable name.

+54
May 20 '11 at 22:55
source share

The file is probably not readable in the world.

EDIT: indeed. Try to do this:

 Uri uri = Uri.parse("file://" + file.getAbsolutePath()); 
+12
May 20 '11 at 22:20
source share



All Articles