到目前为止,我已经找到一个办法让logcat的和正在解决该...现在
在主要活动的onCreate调用此方法;
public static void saveLogcatToFile(Context context) {
File outputFile = new File(context.getFilesDir(), "logcat.txt");
try {
@SuppressWarnings("unused")
Process process = Runtime.getRuntime().exec("logcat -df " + outputFile.getAbsolutePath());
} catch (IOException e) {...
在另一个Activity的onCreate中使用logcat填充TextView;
public static String readLogcatFromFile(Context context) {
File logFile = new File(context.getFilesDir(), "logcat.txt");
if (logFile.exists() == false) { ...
String logContents = context.getString(R.string.EMPTY_STRING);
FileInputStream fileInStream = null;
try {
fileInStream = new FileInputStream(logFile);
logContents = convertStreamToString(fileInStream);
} catch (Exception e) { ...
} finally { ...
fileInStream.close();
}
return logContents;
}
private static String convertStreamToString(InputStream is) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
reader.close();
return sb.toString();
}
日志为每次运行追加,直到您卸载(这会删除日志文件)。 我发现它特别有用,当我打破东西,我的应用程序刚刚在启动时死掉,因为我可以恢复到之前的提交并在日志中查看看看发生了什么