2014-09-10 132 views
17

方案

我已经发布了一个Android应用程序的测试版本几个朋友从设备发送日志条目。现在,我想修复测试期间出现的一些错误。Android的logcat的:使用电子邮件

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

是否有应用程序通过电子邮件发送其logcat的条目的方式吗?

澄清

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

你读过这https://github.com/ACRA/acra? – deniz 2014-09-10 12:37:32

+0

[发送一个App的logcat的输出到的emailadress](http://stackoverflow.com/questions/2852181/send-logcat-output-of-an-app-to-an-emailadress) – avalancha 2015-11-04 08:42:29

回答

19

调用此方法onDestory您的主要活动。

public void SendLoagcatMail(){ 

    // 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[] = {"[email protected]"}; 
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

尼斯的可能的复制。我甚至可以将它附加到一个按钮上,这样用户就可以在我请求时将日志发送给我。 – 2014-09-10 12:48:00

+0

是的。 请将此答案标记为已接受,如果它为您工作。 – 2014-09-10 12:49:26

+0

当然,我会尽快做到这一点。你有任何想法,如果它需要根或其他特殊权限? – 2014-09-10 12:53:23

0

这听起来像RemoteLogger正是你需要

https://github.com/sschendel/RemoteLogger

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

库提供挂钩来启动,停止,发送和删除日志文件。

相关问题