I need to read and filter logcat logs within my application, of others applications. I found other questions and the most useful if Read logcat programmatically within application.
So I tried to write my code, but the result is always the same, that is it returns the logcat logs that made until the application was started.
public void getLog() {
edLog.setText("");
Log.e("imgspa", "ciao");
try {
//Process logcat = Runtime.getRuntime().exec(new String[]{"logcat", "-d", "*:I"});
//Process logcat = Runtime.getRuntime().exec(new String[]{"logcat", "-d", "B4A:I"});
//Process logcat = Runtime.getRuntime().exec(new String[]{"logcat", "-d", "-v", "time", "-e", "*VFY*"});
//Process logcat = Runtime.getRuntime().exec(new String[]{"logcat", "-d", "-v", "time", "*:I"});
//Process logcat = Runtime.getRuntime().exec(new String[]{"logcat", "-d"});
Process logcat = Runtime.getRuntime().exec(new String[]{"logcat", "-d", "-v", "threadtime", "*:*"});
BufferedReader br = new BufferedReader(new InputStreamReader(logcat.getInputStream()));
String line;
final StringBuilder sb = new StringBuilder();
String separator = System.getProperty("line.separator");
sb.append("inizio");
sb.append(separator);
while ((line = br.readLine()) != null) {
sb.append(line);
sb.append(separator);
}
sb.append("fine");
edLog.setText(sb.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
As you can see I tried different solutions but no one can help me. I need to get the logcat, where the application name is "B4A".
Let me point out that: - I have a rooted device - I already added the READ_LOGS permissions