我需要将整个Logcat写入sdcard而不是过滤后的Logcat。所以我试着这样做
String[] cmd ={"/system/bin/logcat " +"-f"+" /sdcard/d.txt"};
Log.d("NTK","cmd string"+cmd);
Runtime run = Runtime.getRuntime();
Process pr;
try {
pr = run.exec(cmd);
pr.waitFor();
BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = "";
while ((line=buf.readLine())!=null) {
System.out.println(line);
Log.i(NTL, "lines"+line);
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我也在清单文件中提供了所有权限。
无法将logcat写入sdcard。
答案 0 :(得分:2)
您可以拥有this
阅读日志的教程。要在日志中写入日志,您只需使用FileWriter
给文件路径指定文件名。
try {
File root = Environment.getExternalStorageDirectory();
if (root.canWrite()) {
File gpslogfile = new File(root, "log.txt");
FileWriter gpswriter = new FileWriter(gpslogfile, true);
BufferedWriter out = new BufferedWriter(gpswriter);
out.append(DataToWrite);
out.close();
}
} catch (IOException e) {
Log.d("Log: ", "Could not write file " + e.getMessage());
}