//send
email with log file.
// attach file path.
File file = new File("/sdcard/logcat.txt");
String[] addrStrings = new String[] { "xxx@xxx.com", "" };
Intent intent = new Intent(Intent.ACTION_SEND);
// email title.
intent.putExtra(Intent.EXTRA_SUBJECT, "force close log:"+file.getName());
// email body.
intent.putExtra(Intent.EXTRA_TEXT, "force close log");
// email address. Note:the address parameter must be String[] type.
intent.putExtra(Intent.EXTRA_EMAIL, addrStrings);
//attach file.
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
if (file.getName().endsWith(".gz")) {
// gz gzip mime
intent.setType("application/x-gzip");
} else if (file.getName().endsWith(".txt")) {
// 纯文本用text/plain的mime
intent.setType("text/plain");
} else {
// 其他则用二进制数据来发送
intent.setType("application/octet-stream");
}
// 调用系统的mail客户端进行发送
startActivity(intent);
// attach file path.
File file = new File("/sdcard/logcat.txt");
String[] addrStrings = new String[] { "xxx@xxx.com", "" };
Intent intent = new Intent(Intent.ACTION_SEND);
// email title.
intent.putExtra(Intent.EXTRA_SUBJECT, "force close log:"+file.getName());
// email body.
intent.putExtra(Intent.EXTRA_TEXT, "force close log");
// email address. Note:the address parameter must be String[] type.
intent.putExtra(Intent.EXTRA_EMAIL, addrStrings);
//attach file.
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
if (file.getName().endsWith(".gz")) {
// gz gzip mime
intent.setType("application/x-gzip");
} else if (file.getName().endsWith(".txt")) {
// 纯文本用text/plain的mime
intent.setType("text/plain");
} else {
// 其他则用二进制数据来发送
intent.setType("application/octet-stream");
}
// 调用系统的mail客户端进行发送
startActivity(intent);
本文介绍了一种在Android设备上通过邮件发送日志文件(logcat.txt)的方法。具体步骤包括创建Intent并设置ACTION_SEND,附加文件路径,指定收件人地址,设置邮件主题和正文,并根据附件类型设置MIME类型。
282

被折叠的 条评论
为什么被折叠?



