2

I am creating a app where i generated a .csv file.Now i sent this file using email, but the mail received is not getting my file as attachment.My code is as follows.

please help me where i am getting wrong.

i have tried this link stackoverflow similar

Button export;

File    csvDirectory= new File(Environment.getExternalStorageDirectory(),"CSVFiles");
        if(!csvDirectory.exists())
        {`enter code here`
            csvDirectory.mkdirs();
        }
        final File csv= new File(csvDirectory, "firstcsv.csv");
        try{
             if(!csv.exists())
             {
              csv.createNewFile();
              }
             path=csv.getPath();

export.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                sendMail();

            }
        });

public void sendMail()
    {
        File f= new File(path);
        u1=Uri.fromFile(f);
        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Person Details");
        sendIntent.putExtra(Intent.EXTRA_STREAM, u1);
        sendIntent.setType("text/html");
        startActivity(sendIntent);
    }
Community
  • 1
  • 1
Jay Vyas
  • 2,674
  • 5
  • 27
  • 58

1 Answers1

0

Try this in sendMail() instead of text/html

sendIntent.setType("text/csv ");
SwapnilPopat
  • 517
  • 5
  • 26