How to send csv file as attachment in android? - android

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!

Related

How to send a String as html attachment in Android mail?

I would like to attach string as html attachment in android mail,how can I achieve this.Kindly help me with a snippet to do this.Thanks a lot.
Use intent to send email like below way .. and if u want to add some string as attachment u have to save that content into some directory with .html ext and later u can add it as attachment into email intent. [This code for idea it may need few modification as per ur app requirement..]
String emailText = "email message";
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.setType("message/rfc822");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "demo#gmail.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Hi");
emailIntent.putExtra(Intent.EXTRA_TEXT, emailText);
String attachContent = "<html> content </html>";
/* this method u have to write, to save the string into html file
into cache or any other dir */
saveFile(getCacheDir()+"/attach.html", attachContent );
File file = new File(root, getCacheWebDir()+"/attach.html");
Uri uri = Uri.fromFile(file);
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));

how to send image via email in android?

I am developing an application in which i have to send an image via email, I tried with
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "xyz#gmal.com");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "message");
emailIntent.setType("image/png");
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.a));
emailIntent.putExtra(Intent.EXTRA_STREAM, uris);
startActivity(emailIntent);
but its giving me as gmail has stopped unfortunately.How can I send an image via email,
Thanks in advance.
Get the image storage path by using the file,
File img = new File(Environment.getExternalStorageDirectory()+"/Android/data/"+getApplicationContext().getPackageName()+"/", imagename+".png");
Convert that file path in to Uri
Uri imageuri = Uri.fromFile(img);
Send the image via email using
Intent send_img = new Intent(Intent.ACTION_SEND);
send_img.putExtra(Intent.EXTRA_EMAIL, "xyz#gmal.com");
send_img.putExtra(Intent.EXTRA_SUBJECT, "email_subject");
send_img.putExtra(Intent.EXTRA_STREAM, imageuri);
send_img.putExtra(Intent.EXTRA_TEXT, "message");
send_img.setType("text/plain");
send_img.setType("image/png");
startActivity(Intent.createChooser(send_img, "Send Email..."));

The mp3 files of my app are not sent through gmail

I have a problem, I'm triying to send a mp3 file to gmail.
My code works good so far for whatsapp, hotmail, bluetooth... but it doesn't work with gmail
This is my code:
File sdCard = Environment.getExternalStorageDirectory();
String path = sdCard.getAbsolutePath() + "/" +"miApp"+"/tono.mp3";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("audio/mp3");
intent.putExtra(Intent.EXTRA_SUBJECT, "Asunto");
intent.putExtra(Intent.EXTRA_TEXT, "Prueba");
intent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:///" + path));
startActivity(intent);
I try with various types of mime but with the same results
"audio/x-mpeg-3"
"video/mpeg"
"video/x-mpeg"
"audio/mpeg"
What's wrong?
This worked for me
Intent i = new Intent(Intent.ACTION_SEND);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("audio/mp3");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/miApp/tono.mp3"));
startActivity(i);

Android email send without attachment

I have to following problem:
I want to send an email with an image attached to it.
I wrote this code:
File file = context.getDir("Files", context.MODE_WORLD_WRITEABLE);
File image = new File(file, "image.jpg");
Uri U = Uri.fromFile(image);
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("image/jpg");
i.putExtra(Intent.EXTRA_STREAM, U);
context.startActivity(Intent.createChooser(i, "Email:"));
The email is sent but there is no attachment.
Does anybody have any idea why the email is sent without the attachment?
EDIT
I have found the answer to my question. Because the image was stored on the internal storage, it did not have enough rights so it could not be sent via email. I've moved my image to externalStorage and now it's working :)
Thanks,
Ark
String smsBody = "Body of the Content";
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/*");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject of the Mail");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, smsBody);
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile("mnt/sdCard/SampleImageFloder/TestImage.png"));
emailIntent.setType("vnd.android.cursor.dir/email");
activity.startActivity(Intent.createChooser(emailIntent,"Email:"));
Try this one -
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{"email"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Test");
//has to be an ArrayList
ArrayList<Uri> uris = new ArrayList<Uri>();
//convert from paths to Android friendly Parcelable Uri's
for (String file : filePaths)
{
File fileIn = new File(file);
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
context.startActivity(emailIntent);
Just see my Existing Answer also

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..
You should use a mime type of .doc documents application/msword.
Try:
emailIntent.putExtra(Intent.EXTRA_STREAM,
Uri.fromFile(file);

Categories

Resources