0%

Android 获取当前应用指定Tag的log

Android 中通过代码获取当前应用的log:

public static Process getProcess() throws IOException {
ProcessBuilder processBuilder=new ProcessBuilder();
List<String> args=new ArrayList<>();
args.add("logcat");
args.add("--pid="+ android.os.Process.myPid());
args.add("*:V");
Process process=processBuilder.command(args).start();
return process;
}

获取指定标签的log:

public static Process getBridgeProcess() throws IOException {
ProcessBuilder processBuilder=new ProcessBuilder();
List<String> args=new ArrayList<>();
args.add("logcat");
args.add("--pid="+ android.os.Process.myPid());
args.add("xxxxxx:I");//这里xxxxxx改成自己的tag即可
args.add("*:S");
args.add("-v");
args.add("raw");
Process process=processBuilder.command(args).start();
return process;
}