Estoy tratando de leer los registros del sistema en mi código para generar algo así como un informe de error. Similar a adb logcat, pero de forma programada.¿Cómo se lee el archivo de registro del sistema en Android?
¿Cómo puedo lograrlo?
Estoy tratando de leer los registros del sistema en mi código para generar algo así como un informe de error. Similar a adb logcat, pero de forma programada.¿Cómo se lee el archivo de registro del sistema en Android?
¿Cómo puedo lograrlo?
Log Collector tiene su código fuente disponible en Google Code. En realidad solo llaman a Logcat. Ver aquí: android-log-collector - SendLogActivity.java
Aquí es la parte clave:
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);
}
podría utilizar el sistema integrado de informe de errores. Más información en mi blog aquí: enlace 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);
[Aquí hay una discusión sobre estos puestos en Meta] (http : //meta.stackexchange.com/q/153352/152134) –
de EboMike conduce ahora a 404, donde se trasladó aquí: http://code.google.com/p/android-log-collector/source/browse/trunk/ src/com/Xtralogic/android/logcollector/SendLogActivity.java? r = 2 – Inoy
(el eslabón de la respuesta se actualiza, también copiado la parte clave en la respuesta) – EboMike