【问题标题】:Android logcat: Send log entries from device using emailAndroid logcat:使用电子邮件从设备发送日志条目
【发布时间】:2014-11-04 02:22:54
【问题描述】:

场景

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

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

该应用是否可以通过电子邮件发送其 logcat 条目?

说明

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

【问题讨论】:

标签: android logcat


【解决方案1】:

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

【讨论】:

  • 不错。我什至可以将它附加到一个按钮上,这样用户就可以在我要求时将日志发送给我。
  • 当然,我会尽快做。您知道它是否需要 root 或其他特殊权限?
  • 这个解决方案过时了吗?我收到一个片段,弹出并显示“没有应用程序可以执行此操作。”
  • 这可以用 emailIntent .putExtra(Intent.EXTRA_STREAM, Uri.fromFile(outputFile)); 修复。但是后来,附件结果是空的(或者 gmail 应用程序告诉我。)
  • @AndyCr15 请参阅github.com/sanskrit-coders/stardict-dictionary-updater/blob/…中的SendLoagcatMail
【解决方案2】:

听起来RemoteLogger 正是你所需要的

https://github.com/sschendel/RemoteLogger

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

库提供了启动、停止、发送和删除日志文件的挂钩。

【讨论】:

  • 你确定它可以发送logcat日志吗?看起来您应该明确添加日志条目
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-13
  • 2011-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多