我已阅读this article。但它似乎大部分文本显示不在我的应用程序。我如何过滤邮件并让它只显示我的应用程序的日志。换句话说,我想在Android Studio中显示它(仅显示来自我的应用程序的错误日志,显示时间戳等):以编程方式读取logcat以获得应用程序
我尝试了类似“logcat -d -v time”的内容,但不起作用。任何想法?谢谢。
我已阅读this article。但它似乎大部分文本显示不在我的应用程序。我如何过滤邮件并让它只显示我的应用程序的日志。换句话说,我想在Android Studio中显示它(仅显示来自我的应用程序的错误日志,显示时间戳等):以编程方式读取logcat以获得应用程序
我尝试了类似“logcat -d -v time”的内容,但不起作用。任何想法?谢谢。
尝试下面的代码只得到您的应用程序的日志。
public final class MyAppLogReader {
private static final String TAG = MyAppLogReader.class.getCanonicalName();
private static final String processId = Integer.toString(android.os.Process
.myPid());
public static StringBuilder getLog() {
StringBuilder builder = new StringBuilder();
try {
String[] command = new String[] { "logcat", "-d", "-v", "threadtime" };
Process process = Runtime.getRuntime().exec(command);
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line;
while ((line = bufferedReader.readLine()) != null) {
if (line.contains(processId)) {
builder.append(line);
//Code here
}
}
} catch (IOException ex) {
Log.e(TAG, "getLog failed", ex);
}
return builder;
}
}
编辑
添加以下权限到你的AndroidManifest
文件
<uses-permission android:name="android.permission.READ_LOGS" />
你总是可以从logcat的自己解析线,而忽略你不希望任何标记。 –