到目前爲止,我已經找到一個辦法讓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();
}
日誌爲每次運行追加,直到您卸載(這會刪除日誌文件)。 我發現它特別有用,當我打破東西,我的應用程序剛剛在啓動時死掉,因爲我可以恢復到之前的提交併在日誌中查看看看發生了什麼