我正在尝试将我的应用程序的日志重定向到sdcard文件.但我没有这样做.我正在尝试这样的事情.
String cmd= "logcat -v time ActivityManager:W myapp:D *:* >\""+file.getAbsolutePath()+"\"";
Runtime.getRuntime().exec(cmd);
Run Code Online (Sandbox Code Playgroud)
我也尝试了-f选项,但它也没有用.
小智 23
这是我的工作版本:
try {
File filename = new File(Environment.getExternalStorageDirectory()+"/logfile.log");
filename.createNewFile();
String cmd = "logcat -d -f "+filename.getAbsolutePath();
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
找到你的日志文件/sdcard/logfile.log
ada*_*amk 21
用于logcat -f <filename>
将其转储到文件系统中的文件.
确保您使用的文件名在SD卡中,即以/sdcard/...
.开头.
另外,为了将参数传递给logcat
程序,您应该传递exec
方法一个字符串数组(而不是一个字符串):
String[] cmd = new String[] { "logcat", "-f", "/sdcard/myfilename", "-v", "time", "ActivityManager:W", "myapp:D" };
Run Code Online (Sandbox Code Playgroud)
最后,如果所有其他方法都失败了,请使用logcat的完整路径:/system/bin/logcat
而不仅仅是logcat
.
归档时间: |
|
查看次数: |
25583 次 |
最近记录: |