0

我正在创建一个文件,然后从我的应用程序在后台将其作为附件邮件发送。一切正常 邮件发送已成功完成,但问题是在创建文件时我将其命名为 abc.csv 并将其文件存储在 dir 中名称,但当我收到附件时,它被命名为<<_mnt_sdcard_MyTest_abc.csv>>。这是我用来获取附件的代码。

 private boolean SendMail() {
  boolean result=false;
  txtAdd=(EditText)findViewById(R.id.txtAdd);
  File folder;
        folder = new File(Environment.getExternalStorageDirectory() + File.separator
              + getString(R.string.app_name));
     boolean var = false;
        if (!folder.exists())
            var = folder.mkdir();
  Mail m = new Mail("abc@gmail.com", "*****"); 
  //String[] toArr = {EmailFetcher.getEmail(this)}; 
  String[] toArr = {txtAdd.getText().toString()};
  m.setTo(toArr); 
  m.setFrom("abc@gmail.com"); 
  m.setSubject("XXXXXXXXX"); 
  m.setBody("XXXXXXXXXXXXXX"); 
  try { 
    m.addAttachment(folder+"/abc.csv"); 
      if(m.send()) {
          result= true;
    } else { 
        result= false;
    } 
  } catch(Exception e) { 
   Log.e("MailApp", "Could not send email", e); 
  } 
  return result;

}

如何设置附件中的文件名。

4

1 回答 1

2

只需使用它对我有用。

public void sendImageInEmail(String filePath) 
    {
        try 
        {
            String html = "<html><body><center>Created By ZalaJanakSinh<center></body></html>";

            String address = "";

            Intent email = new Intent(Intent.ACTION_SEND);
            email.putExtra(Intent.EXTRA_EMAIL, new String[]{ address });
            email.putExtra(Intent.EXTRA_SUBJECT, "Created By Zala JanakSinh");

            //need this to prompts email client only

            email.setType("text/html");
            email.putExtra(Intent.EXTRA_TEXT,  Html.fromHtml(html));

            email.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            email.setType("image/*");                   

            email.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filePath)));
            myContext.startActivity(Intent.createChooser(email, "Choose an Email client :"));
        }
        catch (Exception e) 
        {
            e.printStackTrace();
            System.out.println("Error in SendImageInEmail==>"+e.toString());
        }

祝你好运亲爱的

于 2013-03-18T05:42:10.700 回答