0
我想記錄我的應用程序活動的一些數據,以便在系統中讀取它。數據包括按下按鈕時收集的字符串,浮動等。做這個的最好方式是什麼?在Android中存儲應用程序活動日誌
我想記錄我的應用程序活動的一些數據,以便在系統中讀取它。數據包括按下按鈕時收集的字符串,浮動等。做這個的最好方式是什麼?在Android中存儲應用程序活動日誌
我最終編寫了自己的函數來登錄設備。
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的相關問題是here。
謝謝。該應用程序用於讀取WiFi信號和錄製強度,因此我無法在工作時將其連接到系統。關於Logcollector,有沒有辦法將日誌存儲爲文件,後者是通過訪問而不是郵件/短信? – primpap 2011-04-19 09:58:25
然後,您必須創建您自己的日誌收集器方法,或者您可以嘗試更改LogCollector的代碼。您可以嘗試的另一種方法是將日誌保存在sqllite數據數據庫中,然後嘗試稍後閱讀它們。 – 2011-04-19 10:06:33