如何使用文件附件在Android中发送电子邮件如何使用、发送电子邮件、附件、文件

2023-09-12 23:41:55 作者:逢场作戏丶比的是演技

我要附加.vcf文件与我的邮件和发送通过邮件。但是,邮件接收的地址,而不attachment.I已经使用了低于code,但这样做的code,我不知道我错了。

 尝试{
  字符串filelocation =到/ mnt / SD卡/ contacts_sid.vcf;
  意向意图=新的意图(Intent.ACTION_SENDTO);
  intent.setType(text / plain的);
  intent.putExtra(Intent.EXTRA_SUBJECT,);
  intent.putExtra(Intent.EXTRA_STREAM,Uri.parse(文件://+ filelocation));
  intent.putExtra(Intent.EXTRA_TEXT,消息);
  intent.setData(Uri.parse(电子邮件地址:));
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

  activity.startActivity(意向);
  activity.finish();
  }赶上(例外五){
     的System.out.println(是例外,提出了发送邮件时+ E);
}
 

解决方案

使用下面的code到发送邮件

 字符串filelocation =到/ mnt / SD卡/ contacts_sid.vcf;
意图emailIntent =新的意图(Intent.ACTION_SEND);
//类型设置为电子邮件
emailIntent .setType(vnd.android.cursor.dir /电子邮件);
字符串[] = {asd@gmail.com};
emailIntent .putExtra(Intent.EXTRA_EMAIL,到);
//附件
emailIntent .putExtra(Intent.EXTRA_STREAM,filelocation);
//邮件主题
emailIntent .putExtra(Intent.EXTRA_SUBJECT,主题);
startActivity(Intent.createChooser(emailIntent,发送电子邮件......));
 
智能手机里的电子邮件怎样创建和发送

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

String filelocation="/mnt/sdcard/contacts_sid.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..."));

 
精彩推荐
图片推荐