0

我想记录我的应用程序活动的一些数据,以便稍后在系统中读取它。数据包括按下按钮时收集的字符串、浮点数等。做这个的最好方式是什么?

4

2 回答 2

1

我最终编写了自己的用于登录设备的函数。

public static BufferedWriter out;
    private void createFileOnDevice(Boolean append) throws IOException {
            /*
             * Function to initially create the log file and it also writes the time of creation to file.
             */
            File Root = Environment.getExternalStorageDirectory();
            if(Root.canWrite()){
                 File  LogFile = new File(Root, "Log.txt");
                 FileWriter LogWriter = new FileWriter(LogFile, append);
                 out = new BufferedWriter(LogWriter);
                 Date date = new Date();
                 out.write("Logged at" + String.valueOf(date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + "\n"));
            }
        }

public void writeToFile(String message){
        try {
            out.write(message+"\n");
        } catch (IOException e) {
            e.printStackTrace();
        }

关于 SO 的相关问题在这里

于 2012-12-07T23:08:54.203 回答
0

Logcollector是您的选择,但您需要先在您的设备上安装它。

同样,您可以通过 adb 保存活动日志

adb shell logcat > your_log_file.txt从命令提示符运行。

于 2011-04-19T09:54:30.537 回答