I want to attach .vcf file with my mail and send through the mail. But the mail is received on the address without the attachment.I have used the below code but the code for this and i don't know where i am wrong.
try {
String filelocation="/mnt/sdcard/contacts_sid.vcf";
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse( "file://"+filelocation));
intent.putExtra(Intent.EXTRA_TEXT, message);
intent.setData(Uri.parse("mailto:"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(intent);
activity.finish();
} catch(Exception e) {
System.out.println("is exception raises during sending mail"+e);
}
Use the below code to sent a mail
Folder_name is the name of file in your Internal Storage of your phone. (ACTUALLY EXTERNAL_STORAGE). file_name is the name of the file you want to send.
The example on the official Android site worked for me. All what is need it to add the
as done in Agarwal's answer
SENDTO doesnt support attachment. I have added my answer using Provider to read the file information. Its in Kotlin.