-1

我将在邮件中附加“.csv”并发送。但面临 csv 文件在接收方不可用的问题。

我尝试了太多 Mime 类型

application/octet-stream, text/comma-separated-values, text/csv, application/csv, application/excel, application/vnd.ms-excel, application/vnd.msexcel

但该文件未随邮件附上。

下面是我用来发送邮件的代码

public boolean sendEmail() {
    boolean success = false;
    Intent intentSendMail = new Intent(Intent.ACTION_SEND);

    File mydir = getApplicationContext().getDir(Global.FOLDERNAME, Context.MODE_PRIVATE); 
    File fileWithinMyDir = new File(mydir, Global.FILENAME); 
    if (!fileWithinMyDir.exists() || !fileWithinMyDir.canRead()) {
        Toast.makeText(this, "Attachment Error", Toast.LENGTH_SHORT).show();
        success = false;
    } else {
        intentSendMail.setType("text/csv");

        intentSendMail.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fileWithinMyDir));

        intentSendMail.putExtra(Intent.EXTRA_SUBJECT,
                "Subject");

        intentSendMail.putExtra(Intent.EXTRA_TEXT, "Sent from my phone.");

        startActivity(Intent.createChooser(intentSendMail, "E-mail"));

        success = true;
    }
    return success;
}

提前致谢..

4

3 回答 3

2

尝试如下:

String FILE = Environment.getExternalStorageDirectory() + File.separator
        + "Foldername";
   Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
   sendIntent.setType("application/csv");
   sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "");
   sendIntent.putExtra(Intent.EXTRA_SUBJECT, "");
   sendIntent.putExtra(Intent.EXTRA_TEXT, "");
   String temp_path = FILE + "/" + "Filename.csv";
   File F = new File(temp_path);
    Uri U = Uri.fromFile(F);
    sendIntent.putExtra(Intent.EXTRA_STREAM, U);
    startActivity(Intent.createChooser(sendIntent, "Send Mail"));

希望这会帮助你。

于 2013-08-24T05:38:34.960 回答
1

我得到了这个问题的解决方案。下面是解决方案

public boolean sendEmail() {
    String destLocation = "";
    String FILE = Environment.getExternalStorageDirectory()+"";
    destLocation =  FILE + "/" + Global.FILENAME;


    boolean success = false;
    Intent intentSendMail = new Intent(Intent.ACTION_SEND);

    File mydir = getApplicationContext().getDir(Global.FOLDERNAME, Context.MODE_PRIVATE); 
    File fileWithinMyDir = new File(mydir, Global.FILENAME);

    copyFile(Uri.fromFile(fileWithinMyDir).toString(),destLocation);

    if (!fileWithinMyDir.exists() || !fileWithinMyDir.canRead()) {
        Toast.makeText(this, "Attachment Error", Toast.LENGTH_SHORT).show();
        success = false;
    } else {
        intentSendMail.setType("application/csv");
        intentSendMail.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+destLocation));

        intentSendMail.putExtra(Intent.EXTRA_SUBJECT,
                "Test Play file.");
        intentSendMail.putExtra(Intent.EXTRA_TEXT, "");

        startActivity(Intent.createChooser(intentSendMail, "E-mail"));

        success = true;
    }
    return success;
}
于 2013-10-03T08:47:26.660 回答
0

试试这个

emailIntent.setType("plain/text");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/sanket test/siteriskassesment.csv"));

或者

看到这个

于 2013-08-24T05:43:22.993 回答