在Android中存储应用程序活动日志

发布于 2024-11-02 19:23:21 字数 67 浏览 2 评论 0原文

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

I would like to log some data of my application activity so as to read it latter on in the system. The data includes strings, floats etc collected when a button is pressed. What is the best way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傻比既视感 2024-11-09 19:23:21

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

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 的相关问题位于此处

I ended up writing my own function for logging on the device.

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();
        }

The related question on SO is here.

樱花落人离去 2024-11-09 19:23:21

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

保存活动日志

您可以再次通过 adb Run adb shell logcat > 。命令提示符下的 your_log_file.txt

Logcollector is the option for you but you need to install it first on your device.

Again you can save the activity log via adb

Run adb shell logcat > your_log_file.txt from your command prompt.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文