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..
You should use a mime type of .doc documents application/msword.
Try:
emailIntent.putExtra(Intent.EXTRA_STREAM,
Uri.fromFile(file);
Related
I am trying to send a with attachment where the attachment file could be any type of file(like txt,image,pdf etc) from a sd card.
I used these
String filelocation="file:/"+attachment_file_path1.getText().toString();
Intent emailIntent = new Intent(Intent.ACTION_SEND);
// set the type to 'email'
emailIntent.setType("text/plain");
String to[] = {"destination#yahoo.com"};
emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "bodyyyyyyyyy");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(filelocation));
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "my mail");
startActivity(Intent.createChooser(emailIntent , "Send email..."));
N:B: if i print the attachment_file_path1.getText().toString() it shows like "/storage/sdcard0/myfolder/my.txt"
my email is sent to the destination but my attachment is not sent.
How can i solve the problem??
Change your emailIntent.setType(text/plain) to emailIntent.setType("*/*") for allowing to send any file type.
Path format is :
file:///sdcard/DumbDumpers/DumbDumper.jpg
you need the extra / as this points to the root directory, i.e.:
file:// + /sdcard/DumbDumpers/DumbDumper.jpg
combined as
file:///sdcard/DumbDumpers/DumbDumper.jpg
In the above snippet you need:
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ sPhotoFileName));
I have created the backup file for the SQLite Database i have used in my application. All i want is to send this backup file through email. I have implemented the file sending Intent but when they open, it says, you can only send files like (Image, Coarse Location etc.)
String pathname = Environment.getExternalStorageDirectory().getAbsolutePath();
String filename = "/Android/data/<package-name>/databases/hello.db";
File file=new File(pathname, filename);
Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_SUBJECT, "Database Backup");
i.putExtra(Intent.EXTRA_TEXT, "Hey there, database successfully sent.");
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));`i.setType("text/plain");
startActivity(Intent.createChooser(i, "Your email id"));
The problem is due to Security reason, you can't email data from data folder, SO before emailing export it to SD card and then send, It should work.
Happy Coding !!!
Setting text/plain as attachment type probably causes email client to attempt to preview file as text. You should use other MIME type, such as "application/octet-stream", or even "any" mask - "*/*".
Here is an extremely dirty and simple snippet, that works just fine for me:
File dbFile = new File(Environment.getExternalStorageDirectory(), "example.db");
SQLiteDatabase.openOrCreateDatabase(dbFile, null);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, "example text");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "database sending example");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(dbFile));
startActivity(shareIntent);
I know this question is already ask in the stack overflow, and I looked around them but don't get any clue. Actually I have written code for sending an image file as an attachment to my mail and its working fine. The code I used for sending an image file as an attachment is shown below. Can anyone tell me what are the changes I need to do to send the image file in the body of mail? Any clue will be helpful.
Code for sending the image as an attached file
Uri imageUri = Uri.parse("content://" + CachedFileProvider.AUTHORITY + "/" + fileNameArray.get(position));
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("image/png");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(i, "Send email"));
only work in device not in android emulator..
http://blogingtutorials.blogspot.com/2010/12/send-email-with-attached-file-in.html
Try using the following intent:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/jpeg");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]
{"me#gmail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Test Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"go on read the emails");
Log.v(getClass().getSimpleName(), "sPhotoUri=" + Uri.parse("file:/"+ sPhotoFileName));
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ sPhotoFileName));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
Hi i am developing an android application with email functionality. Here i need to send a CSV file from my path data/data/mypackage/files folder. I am storing the csv file there.It is saving there good.My csv file size is just 245 bytes only. But when i tried to send that file throught mail functionality of android is displaying "File too Large to attach.." message is displaying.
Here is my code:
String filelocation="file:///data/data/my package/files/excerDB.zip";
final Intent emailIntent = new
Intent(android.content.Intent.ACTION_SEND);
emailIntent .setType("plain/text");
emailIntent .putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"purpletalk.raghu#gmail.com"});
emailIntent .putExtra(android.content.Intent.EXTRA_SUBJECT, "Attendence Report");
emailIntent .putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse(filelocation));
startActivity( emailIntent);
But it is not working for me. Please advice me how can i send my file as a attachment to mail in my application.
i hope this code will help u
String FILE = Environment.getExternalStorageDirectory() + File.separator
+ "Foldername";
Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
// sendIntent.setType("text/html");
sendIntent.setType("application/csv");
sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "");
sendIntent.putExtra(Intent.EXTRA_TEXT, "");
String temp_path = FILE + "/" + "Filename.csv";
File F = new File(temp_path);
Uri U = Uri.fromFile(F);
sendIntent.putExtra(Intent.EXTRA_STREAM, U);
startActivity(Intent.createChooser(sendIntent, "Send Mail"));
Enjoy this code!
Im using the following code to send audio-files through email, dropbox +++..
This is not giving me the option to send the same file through MMS..
Anyone know how to attach it to a MMS and let the user send if he/she wants?
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/3gpp");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + aFile));
startActivity(Intent.createChooser(share, "Send file"));
you can used this code..
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
sendIntent.putExtra("address", "9999999999");
sendIntent.putExtra("sms_body", "if you are sending text");
final File file1 = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),"Downloadtest.3gp");
Uri uri = Uri.fromFile(file1);
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
sendIntent.setType("video/3gp");
startActivity(Intent.createChooser(sendIntent, "Send file"));
you have to used your appropriate set type .if audio then audio/*,image then image/png
This code work my samsung nexus,ace 5830 but not working htc amaze.If any one found any solution then please give snippet.