helloDroid
helloDroid

Reputation: 654

send .doc file as an attachment to mail

i want to send a .doc file as an attachment via email.

i am using the code below:

final Intent emailIntent = new Intent(
                                android.content.Intent.ACTION_SEND);

                        emailIntent.setType("plain/text");

                        emailIntent.putExtra(
                                android.content.Intent.EXTRA_SUBJECT,
                                "Song Pad.");

                        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                                "Please see the attached document.");

                        final File file = new File(dirPath + "/" + filename
                                + ".doc");
                        emailIntent.putExtra(Intent.EXTRA_STREAM,
                                Uri.parse("file://" + file.getAbsolutePath()));

                        MainActivity.this.startActivity(Intent.createChooser(
                                emailIntent, "Send Email..."));

the attachment goes successfully to email but when i open it on device it shows message

Unable to find viewer for plain/text.

on the other hand when i send doc file not via my app then it opens perfectly.

please guide . i think there is little mistake.. thanks..

Upvotes: 0

Views: 618

Answers (2)

Peter Knego
Peter Knego

Reputation: 80340

You should use a mime type of .doc documents application/msword.

Upvotes: 1

Thommy
Thommy

Reputation: 5407

Try:

emailIntent.putExtra(Intent.EXTRA_STREAM,
                            Uri.fromFile(file);

Upvotes: 0

Related Questions