【问题标题】:Write a csv file and send it with other name as attachment in android编写一个csv文件并在android中以其他名称作为附件发送
【发布时间】:2016-01-30 20:35:37
【问题描述】:

以下代码正在保存Data.csv文件并通过邮件发送。

我想用当前名称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[]{"test@yahoo.gr"}); 
sendIntent.putExtra(Intent.EXTRA_STREAM, u1); 
sendIntent.setType("text/html"); startActivity(sendIntent);

【问题讨论】:

  • 你在哪里设置 newname.csv?
  • Data.csv 和 newname.csv 是同一个文件,但我想保存为 data.csv 并作为附件发送,名称为 newname.csv
  • 对,但是您要在哪里尝试将 newname.csv 设置为附件?在您的代码中没有尝试实现这一点
  • 我为此添加了代码,但不起作用

标签: java android csv sendmail file-rename


【解决方案1】:

也许你只是为了

1-将 Data.csv 复制到 newname.csv

2-发送 newname.csv

3-删除文件 newname.csv (如果发件人是活动,则 startForResult(使用 startActivityForResult 启动邮件程序意图)并删除 ActivityResult 上的文件)

【讨论】:

    猜你喜欢
    • 2013-05-22
    • 2018-10-20
    • 2013-01-03
    • 2011-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-21
    相关资源
    最近更新 更多