开发者

Storing application activity log in Android

I would like to log some data of my application activit开发者_如何学Goy 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜