Help us understand the problem. What is going on with this article?

CSVを作成してGmailに添付する方法

More than 5 years have passed since last update.

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" />
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away