Я пытаюсь отправить электронное письмо с приложением из моего приложения для Android. Но электронная почта как-то выходит без вложения, хотя файл существует. В представлении отправки электронной почты он показывает вложение (с размером файла даже), но после отправки на стороне приемника нет вложения. Любая идея почему?Вложения не могут быть отправлены по электронной почте
private void copyFileToExternal() throws IOException {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "data/com.dw.inspectionhelperNSTC/databases/Inspection.db";
String backupDBPath = "Inspection_backup.db";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (currentDB.exists()) {
FileChannel src = new FileInputStream(currentDB)
.getChannel();
FileChannel dst = new FileOutputStream(backupDB)
.getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
Toast.makeText(getBaseContext(), "testing", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getBaseContext(), "not exist", Toast.LENGTH_LONG).show();
System.out.println("currentDB does not exists");
}
} else {
Toast.makeText(MainActivity.this,
"NO SDcard so unable to send the database backup",
Toast.LENGTH_SHORT).show();
System.out.println("sdcard cant write");
}
} catch (Exception e) {
Toast.makeText(getBaseContext(), "error", Toast.LENGTH_LONG).show();
System.out.println("exception" + e.getLocalizedMessage());
}
}
private void sendEmail(String email) {
ArrayList<Uri> uris = new ArrayList<Uri>();
// Adding the inspection DB;
File file = new File(Environment.getExternalStorageDirectory(),
"Inspection_backup.db");
Uri path = Uri.fromFile(file);
uris.add(path);
// Adding the stacttrack file with uncaught expection
File file2 = new File(Environment.getExternalStorageDirectory(),
Constant.STACKTRACE_FILE);
Uri path2 = Uri.fromFile(file2);
uris.add(path2);
Intent intent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
intent.setType("application/octet-stream");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"inspection database");
String to[] = { email };
intent.putExtra(Intent.EXTRA_EMAIL, to);
intent.putExtra(Intent.EXTRA_TEXT,
"sending inspection database for reporting");
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivityForResult(Intent.createChooser(intent, "Send mail..."),
1222);
}
Ваш текущий путь дб неправильно его следует бть Environment.getExternalStorageDirectory() + "/ Android/данные/com.dw.inspe .... . »и т. д. –