2013-01-20 22 views
2

我想發送附件的電子郵件在模擬器上保存在SDCard上,但問題是它發送沒有附件的電子郵件。請告訴我在哪裏,我去錯了發送電子郵件與附件在Android

下面是代碼

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
       emailIntent.setType("text/plain"); 
       emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] 
       {"[email protected]"}); 
       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. 

會感謝您的幫助

回答

1

這是因爲你的受助途徑是結合RECT。你的日誌明確指出你做了什麼錯:

/mnt/sdcard/../../data/data/com.example.emailandroid/files//mnt/sdcard/myfile.csv 

決不使用硬編碼路徑,從未 asume你是2個leves根目錄下,從未遍歷目錄,你所示的代碼做的方式。使用Environment.getExternalStorageDirectory()獲取外部存儲器(根本不需要是SD卡),然後附加相對路徑以獲取正確和有效的位置。

+0

現在我得到我的文件名(myfile)錯誤。它用紅線強調它,所以我不能調試我的應用程序。請幫幫我 – CoT