[英]Send email with an attachment in android
我正在嘗試發送帶有附件的電子郵件,該附件保存在模擬器的SDCard上,但是問題是它發送的電子郵件中沒有附件。 請告訴我我哪里出了錯
這是代碼
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]
{"djkgotsod@gmail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Dear Sir");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"Im doing Android");
Log.v(getClass().getSimpleName(), "sPhotoUri=" + Uri.parse("/mnt/sdcard/../.."+getFilesDir()+"/"+myfile));
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("/mnt/sdcard/../.."+getFilesDir()+"/"+myfile));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
這是我的原木貓
01-20 17:59:04.927: E/Trace(31078): error opening trace file: No such file or directory (2)
01-20 17:59:06.117: D/gralloc_goldfish(31078): Emulator without GPU emulation detected.
01-20 17:59:08.917: V/Main(31078): sPhotoUri=/mnt/sdcard/../../data/data/com.example.emailandroid/files//mnt/sdcard/myfile.csv
01-20 17:59:10.077: I/Choreographer(31078): Skipped 112 frames! The application may be doing too much work on its main thread.
01-20 17:59:15.267: I/Choreographer(31078): Skipped 30 frames! The application may be doing too much work on its main thread.
將感謝您的幫助
這是因為您的依戀之路不正確。 您的日志清楚地指出您做錯了什么:
/mnt/sdcard/../../data/data/com.example.emailandroid/files//mnt/sdcard/myfile.csv
永遠不要使用硬編碼的路徑, 永遠不要假設您比根目錄低2個級別, 永遠不要按照顯示的代碼遍歷目錄。 使用Environment.getExternalStorageDirectory()獲取根目錄的外部存儲(根本不需要是SD卡),並附加相對路徑以獲取正確和有效的位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.