how to send .apk file from sdcard via email itent in android? - android

i want to send .apk file from sdcard via email intent but not getting attachment.
see below codei try this code but not working for me..
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { "email id" });
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:/" + "/sdcard/obb/rr.apk"));
emailIntent.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file:/" + "/sdcard/obb/rr.apk"));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
This code says could not attachment and not getting mail.

Try to change the type of your attachment as below:
emailIntent.setType("application/zip");

thanks for help i got the mail using this one.
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("*/*");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"email id"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From My App new 1");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/rr.apk"));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

Don't use hard coded /sdcard/ there is no guarantee that the SD card will have that path
Instead change
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:/" + "/sdcard/obb/rr.apk"));
to
Uri fileUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separatorChar + "obb" + File.separatorChar + "rr.apk"));
emailIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
Also change
emailIntent.setType("text/plain");
to
emailIntent.setType("application/zip");

Related

how to send pdf file to mail in android

I used below coding and sent pdf to mail.This pdf not attached in mail.pls give me any solution.
File PayslipDir = new File(Environment.getExternalStorageDirectory(), "/sample/");
// Write your file to that directory and capture the Uri
String strFilename =string3;
File htmlFile = new File(PayslipDir, strFilename);
// Save file encoded as html
Uri htmlUri = Uri.fromFile(htmlFile);
System.out.println("uri"+htmlUri);
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("application/pdf");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] {});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Pdf attachment");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Hi PDF is attached in this mail. ");
emailIntent.putExtra(Intent.EXTRA_STREAM, htmlUri);
PDFViewerActivity.this.startActivity(Intent.createChooser(emailIntent,"Send mail..."));
below code works fine for me:-
sPhotoFileName=Environment.getExternalStorageDirectory()+"/sankettest/siteriskassesment.png";
send.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/*");
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:///mnt/sdcard/sanket test/siteriskassesment.png"));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
});
Hope this works
emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("application/pdf");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{strEmail});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From My App");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/MyPdf.pdf"));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
You need to change
emailIntent.setType("application/pdf");
to
emailIntent.setType("text/html");
I hope it will be helpful !!

How do I attach a .txt file to an email?

I am fairly new to android and I am having a problem with the email. I am trying to attach a text file to an email and send it, but when I do I get a "File too large" error. This is my first time setting up email within an application, can someone please help?
Code:
File myFile = new File(Environment.getExternalStorageDirectory() + "/test.txt");
Uri uri = Uri.fromFile(myFile);
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String aEmailList[] = { "person#gmail.com" };
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test");
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is a test.");
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(emailIntent);
Hello , try this one.
public void sendMail(String[] mailTo,String[] cc,String subject, String body, String attachmentFilePath)
{
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);
emailIntent.setType("plain/text");
if(mailTo!=null)
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,mailTo);
if(cc!=null)
emailIntent.putExtra(android.content.Intent.EXTRA_CC, cc);
if(subject!=null)
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
if(body!=null)
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));
if(mailTo!=null)
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+attachmentFilePath));
context.startActivity(emailIntent);
}

Email Attachment images cant Send

Written a code for send an email along attachment. Once I sent this email it added a garbage value in attachment.
Attached part was encoded in different format.
Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/html");
i.putExtra(Intent.EXTRA_EMAIL, new String[] {"user_one#example.com", "user_two#example.com" });
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + sPhotoFileName));
i.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(mailBody));
startActivity(Intent.createChooser(i, "Send mail..."));
Expected:
It should a attached images files other than encoded string.
Any help would highly appreciate .
Thanks in advance.
File jpegfile = new File(imageDir, "yourfilename.jpeg");
Uri jpegurl = Uri.fromFile(jpegfile);
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("image/jpeg"); //
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "mailid#domain.com" });
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Mail Subject");
intent.putExtra(android.content.Intent.EXTRA_CC, new String[] { "mailid#domain.com" });
intent.putExtra(Intent.EXTRA_TEXT, "Mail body text");
intent.putExtra(Intent.EXTRA_STREAM, jpegurl);
You need to set your intent type to handle images properly, assuming it is a png, as follows.
Intent emailIntent = new Intent(Intent.ACTION_SEND, Uri.fromFile(temp));
emailIntent.setType("image/png");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_share_subject));
emailIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.email_share_message));
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(temp));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
if u Send Jpg image on sen mail...just write i.setType("image/jpeg"); and send any file just write i.setType("image/*");
i've done for send any file from SD card with mail attachment..
Intent sendEmail= new Intent(Intent.ACTION_SEND);
sendEmail.setType("rar/image");
sendEmail.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new
File("/mnt/sdcard/download/abc.rar")));
startActivity(Intent.createChooser(sendEmail, "Email:"));

How to send image file in the body of the email

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..."));

Email with attachment

i am trying to send an email with an attachment using intent.
the file is a pdf stored in the raw folder. it is less than 200k.
but it shows file too large to attach. Y?
help me pls..
Intent in = new Intent(Intent.ACTION_SEND);
in.setType("application/pdf");
in.putExtra(Intent.EXTRA_EMAIL,new String[]{email.getText().toString()});
in.putExtra(Intent.EXTRA_SUBJECT, "Android Development Course");
Uri uri = Uri.parse("android.resource://deepak.android.samples/raw/android");
in.putExtra(Intent.EXTRA_STREAM,uri);
startActivity(Intent.createChooser(in, "Sending email.."));
use this method
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[]{"emailaddress"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Body");
String rawFolderPath = "android.resource://" + getPackageName()
+ "/" + R.raw.shortcuts;
// Here my file name is shortcuts.pdf which i have stored in /res/raw folder
Uri emailUri = Uri.parse(rawFolderPath );
emailIntent.putExtra(Intent.EXTRA_STREAM, emailUri);
emailIntent.setType("application/pdf");
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

Categories

Resources