Я видел несколько потоков на этом сайте, обсуждающих отправку электронной почты с вложениями в android. Я пробовал все методы, обсуждаемые здесь , здесь и здесь .
Я создаю файл csv с помощью кода и сохраняю этот файл во внутреннем хранилище Android. Затем я хочу отправить этот файл в виде вложения по электронной почте. Письмо отправлено, я получаю его без вложений. Вот что я сделал.
String columnString = "\"Person\",\"Gender\",\"Street1\",\"PostOfice\",\"Age\"";
String dataString = "\"" + currentUser.userName +"\",\"" + currentUser.gender + "\",\"" + currentUser.street1 + "\",\"" + currentUser.poNumber.toString() + "\",\"" + currentUser.age.toString() + "\"";
String combinedString = columnString + "\n" + dataString;
File file = new File(this.getCacheDir()+ File.separator + "Data.csv");
try {
FileOutputStream out = new FileOutputStream(file);
out.write(combinedString.getBytes());
out.close();
} catch (IOException e) {
Log.e("BROKEN", "Could not write file " + e.getMessage());
}
Uri u1 = Uri.fromFile(file);
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Person Details");
sendIntent.putExtra(Intent.EXTRA_STREAM, u1);
sendIntent.setType("text/richtext");
startActivity(sendIntent);
Я попытался изменить настройки mime на «text / html» и «text / richtext» и т. Д. Но пока не повезло. Может ли кто-нибудь сказать мне, что я делаю неправильно?