Android logcat:使用电子邮件从设备发送日志条目

时间:2014-09-10 12:21:26

标签: android logcat

方案

我已经向几个朋友发布了Android应用的测试版。现在,我想修复测试期间出现的一些错误。

我已经设置了第三方崩溃报告实用程序,因此我可以轻松处理应用程序崩溃。但是,有一些错误的行为不会导致崩溃。在这些情况下,我想检查应用程序日志,看看出了什么问题。

应用程序是否有办法通过电子邮件发送其logcat条目?

澄清

  • 有许多日志记录应用程序(android-log-collectorLog Viewer (logcat))可以检查和显示logcat条目。但是,自Android 4.1以来,这些应用无法访问其他应用的日志。
  • 我不介意在设备中占用大量空间 - 此功能仅适用于Beta测试人员。
  • 解决方案应该不使用root或任何其他特殊权限。

2 个答案:

答案 0 :(得分:25)

在主要活动的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..."));
 }

答案 1 :(得分:0)

听起来RemoteLogger正是您所需要的

https://github.com/sschendel/RemoteLogger

  

将调试日志记录捕获到用户可以通过电子邮件轻松发送给您的文件。这是为了解决用户报告的不可重现的错误而创建的。要明确的是,日志记录已被放入发布的应用程序版本中,以测试用户进行故障排除。删除了最终的生产代码。

     

Library提供了启动,停止,发送和删除日志文件的钩子。