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