2016-01-30 17 views
1

以下代碼正在努力保存Data.csv文件並通過郵件發送。編寫一個csv文件,並以其他名字作爲附件發送給android

我想將文件保存爲當前名稱Data.csv,然後以其他名稱發送此文件。例如,newname.csv

代碼發送newname.csv,但它被保存在設備中作爲Data.csv。關於我做錯什麼的想法?

這裏是我的代碼:

/* Making A New File */ 
File dir = new File(root.getAbsolutePath() + "/FolderData"); 
dir.mkdirs(); 
file = new File(dir, "Data.csv"); 
out = new FileOutputStream(file); out.write(combinedString.getBytes()); 

//want to send the file Data.csv that is saved but with other name 
    File dir = new File(root.getAbsolutePath() + "/DeltioData"); 
      File file2 = new File(dir,"newname.csv"); 
      File Nf=file; 
      Nf.renameTo(file2); 
        // 

Uri u1 = Uri.fromFile(Nf); Intent sendIntent = new Intent(Intent.ACTION_SEND); 

sendIntent.putExtra(Intent.EXTRA_SUBJECT, "any subject"); 
sendIntent.putExtra(Intent.EXTRA_TEXT, "Text"); 
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"}); 
sendIntent.putExtra(Intent.EXTRA_STREAM, u1); 
sendIntent.setType("text/html"); startActivity(sendIntent); 
+2

WHere你設置newname.csv? – Alfabravo

+0

Data.csv和newname.csv是相同的文件,但我想保存爲data.csv並以附件形式發送,名稱爲newname.csv – Apollon

+0

沒錯,但是你在哪裏設置newname.csv到attatchment?沒有線路試圖在您的代碼中實現該功能 – Alfabravo

回答

0

也許你只是

1拷貝Data.csv到newname.csv

2發送newname.csv

3 - 刪除文件newname.csv (如果發件人是活動,startForResult(啓動郵件程序意圖with startActivityForResult)並刪除文件上的ActivityResult)

相關問題