2010-07-22 122 views

回答

6

日志收集器的源代码在Google Code上可用。他们实际上只是调用logcat。在这里看到:android-log-collector - SendLogActivity.java

这里是关键部分:

ArrayList<String> commandLine = new ArrayList<String>(); 
commandLine.add("logcat");//$NON-NLS-1$ 
commandLine.add("-d");//$NON-NLS-1$ 
ArrayList<String> arguments = ((params != null) && (params.length > 0)) ? params[0] : null; 

if (null != arguments){ 
    commandLine.addAll(arguments); 
} 

Process process = Runtime.getRuntime().exec(commandLine.toArray(new String[0])); 
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); 

String line; 
while ((line = bufferedReader.readLine()) != null){ 
    log.append(line); 
    log.append(App.LINE_SEPARATOR); 
} 
+1

EboMike的链接后,导致404,在这里它感动:http://code.google.com/p/android-log-collector/source/browse/trunk/在我的博客点击此处了解详情src/com/xtralogic/android/logcollector/SendLogActivity.java?r = 2 – Inoy 2012-10-11 09:25:30

+0

(答案中的链接已更新,我也将关键部分复制到答案中) – EboMike 2013-11-12 00:24:07

0

你可以使用内置的错误报告系统。 http://blog.tomtasche.at/2012/10/use-built-in-feedback-mechanism-on.html

ApplicationErrorReport report = new ApplicationErrorReport(); 
report.packageName = report.processName = getApplication() 
    .getPackageName(); 
report.time = System.currentTimeMillis(); 
report.type = ApplicationErrorReport.TYPE_CRASH; 
report.systemApp = false; 

ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo(); 
crash.exceptionClassName = e.getClass().getSimpleName(); 
crash.exceptionMessage = e.getMessage(); 

StringWriter writer = new StringWriter(); 
PrintWriter printer = new PrintWriter(writer); 
e.printStackTrace(printer); 

crash.stackTrace = writer.toString(); 

StackTraceElement stack = e.getStackTrace()[0]; 
crash.throwClassName = stack.getClassName(); 
crash.throwFileName = stack.getFileName(); 
crash.throwLineNumber = stack.getLineNumber(); 
crash.throwMethodName = stack.getMethodName(); 

report.crashInfo = crash; 

Intent intent = new Intent(Intent.ACTION_APP_ERROR); 
intent.putExtra(Intent.EXTRA_BUG_REPORT, report); 
startActivity(intent); 
+0

[这是关于Meta上这些帖子的讨论](http ://meta.stackexchange.com/q/153352/152134) – 2012-11-01 21:48:31