Các chủ đề tương tự ở đây không có câu trả lời đã giúp ... Tôi muốn tạo email với tập tin đính kèm, tập tin nằm trong bộ nhớ trong. Đây là mã:Đính kèm tập tin từ bộ nhớ trong vào email
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{email});
i.putExtra(Intent.EXTRA_SUBJECT, "Smart Weight Tracker");
i.putExtra(Intent.EXTRA_TEXT , "CSV file is in attachment");
Uri uri;
if(useExternal){
uri = Uri.fromFile(new File(this.getExternalFilesDir(null),fname));
}
else{
File f = new File(this.getFilesDir(),fname);
f.setReadable(true, false);
f.setWritable(true, false);
uri = Uri.fromFile(f);
}
i.putExtra(Intent.EXTRA_STREAM, uri);
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
Nó hoạt động hoàn hảo với bộ nhớ ngoài, nhưng tôi không đính kèm khi sử dụng bộ nhớ trong. Tôi đã kiểm tra - mở tệp, (đó là thời lượng trong ứng dụng của tôi bằng cách hiển thị Bánh mì nướng - là OK,> 0).
tôi viết nó theo cách này:
OutputStreamWriter out =
new OutputStreamWriter(con.openFileOutput(fname, Context.MODE_WORLD_READABLE));
Trong logcat tôi thấy
I/Gmail (28480): >>>>> Attachment uri: file:///data/data/Android.MyApp/files /31.10.2011.csv
I/Gmail (28480): >>>>> type: text/plain
I/Gmail (28480): >>>>> name: 31.10.2011.csv
I/Gmail (28480): >>>>> size: 0
Size == 0!
Bất kỳ ý tưởng?
Thanx ... nhưng kết quả giống nhau. Kích thước 0 trong logcat, không có tệp đính kèm – Maep