我想將我的應用程序logcat事件保存在SD卡上的文本文件中。 我的驚人的應用程序在我的和我的朋友設備中正常工作,但其他應用程序有錯誤。 例如,他們說在應用程序中的警報是在錯誤的時間,但我沒有看到我和我的朋友設備中的這個錯誤。 由於這個問題和其他問題,我想保存所有事件logcat相關我的應用程序,atomatically。所以他們發送日誌文件給我解決問題。 我該怎麼做? 謝謝 對不起我的英文不好在sd上的文件中保存應用程序事件(logcat)
回答
您可以通過以下獲得的logcat:
static final int BUFFER_SIZE = 1024;
public String getLogCat() {
String[] logcatArgs = new String[] {"logcat", "-v", "time"};
Process logcatProc = null;
try {
logcatProc = Runtime.getRuntime().exec(logcatArgs);
}
catch (IOException e) {
return null;
}
BufferedReader reader = null;
String response = null;
try {
String separator = System.getProperty("line.separator");
StringBuilder sb = new StringBuilder();
reader = new BufferedReader(new InputStreamReader(logcatProc.getInputStream()), BUFFER_SIZE);
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
sb.append(separator);
}
response = sb.toString();
}
catch (IOException e) {
}
finally {
if (reader != null) {
try {
reader.close();
}
catch (IOException e) {}
}
}
return response;
}
可以那麼這String
保存的SD卡。
我如何過濾logcat到我的應用程序? –
將這些標籤作爲附加參數添加到logcatArgs例如{「logcat」,「-v」,「time」,「YourTag:V AnotherTag:V MoreTag:V *:S」};你指出你想要的等級之後:(在這種情況下詳細標籤:V)和*:S使其他一切都保持沉默。 – Dororo
我該如何動態地做到這一點? –
這種類型的功能已經由ACRA Android庫實現。該庫檢測崩潰,並將崩潰信息發送到Google文檔電子表格或您自己的目的地。
我不能去ACRA鏈接,因爲谷歌攔截它爲我的IP。和我的應用程序沒有崩潰,我的應用程序工作報警錯誤。 –
您可以通過以下獲得的logcat:
static final int BUFFER_SIZE = 1024;
public String getLogCat() {
String[] logcatArgs = new String[] {"logcat", "-v", "time"};
Process logcatProc = null;
try {
logcatProc = Runtime.getRuntime().exec(logcatArgs);
}
catch (IOException e) {
return null;
}
BufferedReader reader = null;
String response = null;
try {
String separator = System.getProperty("line.separator");
StringBuilder sb = new StringBuilder();
reader = new BufferedReader(new InputStreamReader(logcatProc.getInputStream()), BUFFER_SIZE);
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
sb.append(separator);
}
response = sb.toString();
}
catch (IOException e) {
}
finally {
if (reader != null) {
try {
reader.close();
}
catch (IOException e) {}
}
}
return response;
}
可以那麼這
String
保存的SD卡。
這個來自「Dororo」的回答對我來說不起作用,因爲它由於多行而始終卡住,但我不知道如何解決這個問題。
除非您指定'-d'arg,否則logcat將阻止讀取新日誌。
嘗試
String[] logcatArgs = new String[] {"logcat", "-d", "-v", "time"};
一個線程中執行,以避免ANR的
[如何從logcat的我的日誌輸出到SD卡重定向在Android設備上?(HTTP的- 1. 在Sd卡上保存文件爲Mp3 {Android應用程序}
- 2. 無法保存文件到SD卡android應用程序
- 3. 將文件保存在SD卡上
- 4. 將文件保存在應用程序文件夾中
- 5. 保存文件到SD卡
- 6. 在Android上保存文件,但不保存到SD卡
- 7. 如何保存SD卡中的文件?
- 8. 從應用程序保存文件Android
- 9. 保存文件宿主應用程序
- 10. 在Firebase中保存按鈕點擊事件Android應用程序
- 11. 在Android應用程序中解析SD卡中的json文件
- 12. 保存文件時Silverlight應用程序在Mac上凍結
- 13. 從WP7應用程序訪問SD卡上的文件
- 14. 保存應用程序特定的保存文件C#visual studio
- 15. 保存文件到iphone應用程序的保存箱
- 16. 下載保存在ios應用程序中的文件
- 17. 打開.mobileconfig文件保存在Safari中的應用程序ios
- 18. 在應用程序的保存箱中創建文件夾
- 19. 在iOS 5應用程序中保存文件的位置?
- 20. 保存在C#中的文件,應用程序數據
- 21. 我在哪裏保存Rails應用程序中的.txt文件?
- 22. 保存到程序文件文件夾的文件不存在
- 23. 如何在Windows應用程序中的文件夾中保存文件
- 24. 關閉應用程序後保存的文件不再存在
- 25. 將png文件保存在應用程序圖像文件夾中而不使用保存對話框文件
- 26. 將Logcat輸出保存到文件
- 27. 將文本文件保存到SD卡
- 28. 程序文件保存的文件
- 29. Python:用默認應用程序打開文件並捕獲'保存事件'
- 30. 在文件名中使用特殊字符保存SD卡中的文件
可能重複:// stackoverflow.com/questions/3359692/how-to-redirect-my-log-output-from-logcat-to-the-sd-card-on-an-android-device) – Narkha