【发布时间】:2011-08-07 01:38:35
【问题描述】:
我想实现以下目标,但到目前为止还没有成功
- Android 应用程序首次启动时打开 SD 卡中的文件。
- 将 logcat 输出流式传输到文件。
- 当应用程序退出时,停止 logcat 流。
在我的 ApplicationClass extends Application onCreate() 方法中,我这样做了
wwLogManager.openLogFile();
这是 openLogFile() 中的代码
private static final String LOGCAT_COMMAND = "logcat -v time -f ";
String timestamp = Long.toString(System.currentTimeMillis());
String logFileName = BuildConstants.LOG_LOCATION + "_" + timestamp + ".log";
mLogFile = new File(Environment.getExternalStorageDirectory() + logFileName);
mLogFile.createNewFile();
String cmd = LOGCAT_COMMAND + mLogFile.getAbsolutePath();
Runtime.getRuntime().exec(cmd);
我确实在 sd 卡中获得了日志文件,但这些文件中的日志输出没有我在活动中放置的 Log.i() 调用的任何痕迹。我在这里使用的 logcat 命令是否正确?谢谢!
【问题讨论】:
-
您找到解决方案了吗?
-
是的。我最终使用 BufferedReader 从 Runtime.getRuntime().exec(cmd) 读取输出。
-
您能否在此处发布一个答案,以准确显示您所做的事情,为我和所有其他人的利益?
-
@JPM:请看我刚刚发布的答案...
标签: android file sd-card logcat