场景
我已经向几个朋友发布了一款Android应用的测试版。现在,我想修复测试期间出现的一些错误。
我已经设置了一个第三方崩溃报告工具,所以我可以轻松地处理应用程序崩溃。然而,有一些错误的行为不会导致崩溃。在这些情况下,我想检查应用程序日志,看看哪里出了问题。
有没有办法让应用程序通过电子邮件发送日志记录?
澄清
root
或任何其他特殊应用程序的情况下运行发布于 2014-09-10 20:42:12
在主活动的onDestroy中调用此方法。
public void SendLogcatMail(){
// save logcat in file
File outputFile = new File(Environment.getExternalStorageDirectory(),
"logcat.txt");
try {
Runtime.getRuntime().exec(
"logcat -f " + outputFile.getAbsolutePath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//send file using email
Intent emailIntent = new Intent(Intent.ACTION_SEND);
// Set type to "email"
emailIntent.setType("vnd.android.cursor.dir/email");
String to[] = {"yourmail@gmail.com"};
emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
// the attachment
emailIntent .putExtra(Intent.EXTRA_STREAM, outputFile.getAbsolutePath());
// the mail subject
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(emailIntent , "Send email..."));
}
https://stackoverflow.com/questions/25765366
复制相似问题