如何使用文件附件在Android中发送电子邮件 [英] How to send an email with a file attachment in Android

查看:236
本文介绍了如何使用文件附件在Android中发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要附加.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..."));

这篇关于如何使用文件附件在Android中发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆