前提・実現したいこと
はじめて質問させていただきます、素人同然の初心者ですのでこの場で質問してよいのかも分からないのですが、よろしくお願いいたします。
CSVファイルを作成してGmailに添付したいのですが、’FileNotFoundException’となってしまいます。
以下のコードの実行結果はbtnSend2をタップすると画面に'FileNotFound'と表示されます。
参考にしたページ
https://qiita.com/ueno-yuhei/items/e9147b2b5930fc7c4975
該当のソースコード
android
1 2 ImageButton btnMail = findViewById(R.id.btnSend2); 3 btnMail.setOnClickListener(new View.OnClickListener() { 4 5 @Override 6 public void onClick(View v) { 7 8 String tmpCsvPath = Environment.getExternalStorageDirectory().getPath() + "/tmp.csv"; 9 try { 10 // csvファイル作成 11 12 BufferedWriter bw = new BufferedWriter(new OutputStreamWriter( 13 new FileOutputStream(tmpCsvPath, false), "Shift_JIS")); 14 bw.write("№," + den.getText().toString()); 15 bw.newLine(); 16 bw.write("日付," + da.getText().toString()); 17 bw.newLine(); 18 19 // 中 略 20 21 bw.flush(); 22 bw.close(); 23 24 Intent intent = new Intent(); 25 intent.setAction(Intent.ACTION_SEND); 26 intent.putExtra(Intent.EXTRA_SUBJECT, ""); 27 intent.putExtra(Intent.EXTRA_TEXT, ""); 28 // Gmailにファイルの添付 29 Uri attachments = Uri.parse("file://" + tmpCsvPath); 30 intent.putExtra(Intent.EXTRA_STREAM, attachments); 31 intent.setType("application/*"); 32 intent.setPackage("com.google.android.gm"); 33 try { 34 startActivity(intent); 35 } catch (android.content.ActivityNotFoundException ex) { 36 ex.printStackTrace(); 37 Toast.makeText(CountActivity.this.getApplicationContext(), "client not found", Toast.LENGTH_LONG).show(); 38 } 39 } catch (UnsupportedEncodingException e) { 40 e.printStackTrace(); 41 Toast.makeText(CountActivity.this, "UnsupportedEncoding", Toast.LENGTH_LONG).show(); 42 } catch (FileNotFoundException e) { 43 e.printStackTrace(); 44 Toast.makeText(CountActivity.this, "FileNotFound", Toast.LENGTH_LONG).show(); 45 } catch (IOException e) { 46 e.printStackTrace(); 47 Toast.makeText(CountActivity.this, "IOException", Toast.LENGTH_LONG).show(); 48 } 49 } 50 });
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答4件
あなたの回答
tips
プレビュー