· 7 years ago · Sep 13, 2018, 03:58 PM
1send Email with Attachment as csv file
2/** Called when the activity is first created. */
3@Override
4public void onCreate(Bundle icicle) {
5 super.onCreate(icicle);
6 String dir = "/Android/data/com.pucit/csv/";
7 String fullDir = Environment.getExternalStorageDirectory().toString() + dir;
8 generateCsvFile(fullDir, "data.csv");
9
10 Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),"data.csv"));
11 Log.d("321", "a"+uri.toString());
12
13
14 final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
15 emailIntent.setType("plain/text");
16 emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"ninja9196@gmail.com"});
17 emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Attachment");
18 emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/data.csv"));
19 emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "gmail.com");
20
21 MainActivityActivity.this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
22
23}
24
25private static void generateCsvFile(String dir, String fileName) {
26 try {
27
28 File theDir = new File(dir);
29 theDir.mkdirs();
30
31 FileWriter writer = new FileWriter(dir + fileName);
32
33 writer.append("DisplayName");
34
35 //generate whatever data you want
36
37 writer.flush();
38 writer.close();
39 } catch (IOException e) {
40 Log.i("file", e.getMessage());
41 }
42}