我已经向几个朋友发布了Android应用的测试版.现在,我想修复测试期间出现的一些错误.
我已经设置了第三方崩溃报告实用程序,因此我可以轻松处理应用程序崩溃.但是,有一些错误的行为不会导致崩溃.在这些情况下,我想检查应用程序日志,看看出了什么问题.
有没有办法让应用程序通过电子邮件发送其logcat条目?
root或任何其他特殊权限.小智 26
在主活动的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..."));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12836 次 |
| 最近记录: |