通过使用以下代码,我能够从 Android 应用程序中提取主日志:
String[] LOGCAT_CMD = new String[] {
"logcat",
"-d",
"MyApplication:E",
"*:S"};
Process logcatProc = null;
try {
logcatProc = Runtime.getRuntime().exec(LOGCAT_CMD);
} catch (IOException e) {
e.printStackTrace();
return "";
}
String lineSeparator = System.getProperty("line.separator");
StringBuilder strOutput = new StringBuilder();
try {
InputStream ireader = logcatProc.getInputStream();
int temp;
while ( (temp = ireader.read()) != -1 ){
while ( temp != 64 ){
strOutput.append( (char) temp);
temp = ireader.read();
}
strOutput.append(lineSeparator);
line = strOutput.toString();
writeLine(line);
strOutput = new StringBuilder();
}
但是,当我尝试使用相同的方法提取事件日志时,它不起作用。我不知道问题是什么,但是当我将 LOGCAT_CMD 更改为以下并运行应用程序时,ireader.read() 立即返回 -1 并完成。
String[] LOGCAT_CMD = new String[] {
"logcat",
"-b",
"events",
"-d",
"[1]:I",
"*:S"
};
有人可以帮我吗?