2010-07-22 48 views

Trả lời

6

Nhật ký thu thập có sẵn mã nguồn của họ trên Google Code. Họ thực sự chỉ cần gọi logcat. Xem ở đây: android-log-collector - SendLogActivity.java

Đây là phần quan trọng:

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 bây giờ dẫn đến 404, ở đây, nơi nó di chuyển: http://code.google.com/p/android-log-collector/source/browse/trunk/ src/com/xtralogic/android/logcollector/SendLogActivity.java? r = 2 – Inoy

+0

(Liên kết trong câu trả lời được cập nhật, tôi cũng đã sao chép phần chính vào câu trả lời) – EboMike

0

Bạn có thể sử dụng được xây dựng trong hệ thống báo cáo lỗi. Thông tin thêm về blog của tôi ở đây: link 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

[Đây là cuộc thảo luận về các bài đăng này trên Meta] (http : //meta.stackexchange.com/q/153352/152134) –

Các vấn đề liên quan