Gmailのみの対応
CSVファイルを作成
↓
GmailにIntentを投げる のシンプルな流れ
String tmpCsvPath = Environment.getExternalStorageDirectory().getPath() + "/tmp.csv";
try {
// csvファイル作成
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tmpCsvPath, false), "SJIS"));
bw.write("test1,");
bw.write("test2");
bw.newLine();
for (int i=0;i<=10000;i++) {
bw.write((i + 1) + ",");;
bw.write(Math.random()*10+"");
bw.newLine();
}
bw.flush();
bw.close();
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, "");
intent.putExtra(Intent.EXTRA_TEXT, "");
// Gmailにファイルの添付
Uri attachments = Uri.parse("file://" + tmpCsvPath);
intent.putExtra(Intent.EXTRA_STREAM, attachments);
intent.setType("application/*");
intent.setPackage("com.google.android.gm");
try {
startActivity(intent);
} catch (android.content.ActivityNotFoundException ex) {
ex.printStackTrace();
Toast.makeText(this.getApplicationContext(), "client not found", Toast.LENGTH_LONG).show();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
※追記
AndroidManifest.xmlに以下も追加
<!-- 外部SDカードへの書き込み -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />