我想將.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