i want to send a contact vcf file using the bluetooth and email. I have tried but i keep getting errors. Please help. Thanks
This is my sendByBluetooth method.
public void sendByBluetooth(){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(storage_path) );
startActivity(intent);
}
This is my emailContact method.
public void emailContact() {
Intent sendIntent = new Intent(Intent.ACTION_SEND);
// Add attributes to the intent
sendIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sendIntent.putExtra(Intent.EXTRA_SUBJECT,"subject line");
sendIntent.putExtra(Intent.EXTRA_TEXT,"Body of email");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(storage_path)));
sendIntent.setType("vnd.android.cursor.dir/email");
startActivity(Intent.createChooser(sendIntent,"Email:"));
}
Please Help! Thanks.
For bluetooth you can set the type as intent.setType("text/x-vcard");
public void sendByBluetooth(){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/x-vcard");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(storage_path) );
startActivity(intent);
}
and for emails you could use
String filelocation="/mnt/sdcard/contacts.vcf";
Intent emailIntent = new Intent(Intent.ACTION_SEND);
// set the type to 'email'
emailIntent .setType("vnd.android.cursor.dir/email");
String to[] = {"asd#gmail.com"};
emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
// the attachment
emailIntent .putExtra(Intent.EXTRA_STREAM, filelocation);
// the mail subject
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(emailIntent , "Send email..."));
Just a side note: The.vcf file should be in in your SD card
Related
button2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String emailList[]= {"rufidennis#gmail.com"};
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL,emailList);
intent.putExtra(Intent.EXTRA_SUBJECT,"Email Subject");
intent.putExtra(Intent.EXTRA_TEXT,"file:///android_asset/www/sample3.html");
startActivity(Intent.createChooser(intent,"Choice email APP"));
}
});
I am using buttons onclick listener method to send an email via my app. I have an html file which i want to send as an email content, the location of file is stored in www folder inside assets. How can i send that email as an email content??
Use the below code to sent a mail with file attachement
String filename="file.html";
File filelocation = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), filename);
Uri path = Uri.fromFile(filelocation);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
// set the type to 'email'
emailIntent .setType("vnd.android.cursor.dir/email");
String to[] = {"asd#gmail.com"};
emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
// the attachment
emailIntent .putExtra(Intent.EXTRA_STREAM, path);
// the mail subject
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(emailIntent , "Send email..."));
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType(TEXT_HTML);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,emailTo);
emailIntent.putExtra(android.content.Intent.EXTRA_CC,emailCC);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT,"file:///android_asset/www/sample3.html");
context.startActivity(Intent.createChooser(emailIntent, context.getString(R.string.send_by_email)));
Trying to send mail with attached file - and i don't know why this code is not working .. the mail is not sending
public void SendMailWithAttached(String fileToSend, String mailToSend)
{
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("vnd.android.cursor.dir/email");
sharingIntent.putExtra(Intent.EXTRA_EMAIL, fileToSend);
sharingIntent.putExtra(Intent.EXTRA_STREAM,mailToSend);
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");
startActivity(Intent.createChooser(sharingIntent, "Send email"));
}
Here is what I do to send a file as an attachment:
File effFile = new File(toPath, files[0]);
Uri effU = Uri.fromFile(effFile);
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_STREAM, effU);
startActivity(Intent.createChooser(i, "Email:"));
The i.setType("text/plain"); command didn't work when I tried others.
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:"));
I have this email sending code that does not show a chooser (good). How can I extend it to include a file attachment, without involving a chooser?
// Based on http://stackoverflow.com/questions/3312438
final Intent intent = new Intent(Intent.ACTION_VIEW);
final Uri data = Uri.parse("mailto:user#domain.com?subject=My Sugbject&body=");
intent.setData(data);
startActivity(intent);
try this :
Intent emailintent = new Intent(android.content.Intent.ACTION_SEND);
emailintent.setType("image/jpeg");
emailintent.putExtra(android.content.Intent.EXTRA_TEXT,
"email body here");
emailintent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]
{"test#gmail.com"});
emailintent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Subject here");
String filName="file:///sdcard/photos/estdemo.jpg";
emailintent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:/"+ filName));
this.startActivity(emailintent);
Try Following code,
Intent i = new Intent(Intent.ACTION_SEND);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("image/jpg");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("photo.jpg"));
startActivity(i);
Use the below code to sent a mail
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("vnd.android.cursor.dir/email");
String to[] = "asd#gmail.com";
sharingIntent.putExtra(Intent.EXTRA_EMAIL, to);
sharingIntent.putExtra(Intent.EXTRA_STREAM,filePath);
sharingIntent.putExtra(Intent.EXTRA_SUBJECT,"subject");
startActivity(Intent.createChooser(sharingIntent, "Send email"));
I am not able to pre fill the TO field in Email client to the "to" address mentioned in the extras here:
EmailImage.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent it = new Intent(Intent.ACTION_SEND_MULTIPLE);
it.putExtra(Intent.EXTRA_EMAIL, "toaddress#gmail.com");
it.putExtra(Intent.EXTRA_SUBJECT, "Regarding Policy Info");
it.putExtra(Intent.EXTRA_TEXT, "When is my next Premium due");
//it.setType("text/plain");
it.setType("message/rfc822");
startActivity(it);
}
});
What is the problem?
Thanks
Sneha
You need to put the address in an array:
it.putExtra(Intent.EXTRA_EMAIL, new String[] {"toaddress#gmail.com"});
See here.
I've got something like this and its works:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "some#email.address" });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail body");
startActivity(Intent.createChooser(intent, ""));
When using ACTION_SEND_MULTIPLE,
You have to provide an array of String for Intent.EXTRA_EMAIL Binyamin Sharet shown you.
If the requirement is to provide only one Address then use Intent.ACTION_SEND.
Try this
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{"","your email"});
This worked for me:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "someone#gmail.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, edt_msg.getText().toString());
emailIntent.putExtra(Intent.EXTRA_SUBJECT, edt_subjct.getText().toString());
emailIntent.setType("message/rfc822");
Uri uri = Uri.parse("file://" + file_img_capt);
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(emailIntent);