我想将.vcf文件与我的邮件附加在一起并通过邮件发送。但邮件收到的地址没有附件。我已经使用了下面的代码,但代码为此,我不知道我在哪里错了。如何用Android中的文件附件发送电子邮件
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);
}
一看我的问题... HTTP://stackoverflow.com/questions/12798001/android-how-to-send-multiple-contacts-are-attached-in-single-vcf-file-并发送 – NagarjunaReddy 2012-10-11 06:37:32
您不应使用“硬编码”路径,因为它们可能会因设备而异。我建议你改变文件位置的定义为: File filelocation = new File(Environment.getExternalStorageDirectory()。getAbsolutePath(),filename); 然后定义: Uri path = Uri.fromFile(filelocation);并把它放在你的意图中: emailIntent .putExtra(Intent.EXTRA_STREAM,path); – 2015-11-24 07:52:44
phillip工作正常,emailIntent.putExtra(Intent.EXTRA_STREAM,filelocation)不会为我附加文件,但使用emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse(“file://”+ filelocation))。 – andytrombone 2016-01-10 01:18:28