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 に答える