我正在爲文本視圖中的打印日誌貓信息做一個應用程序。我使用下面的代碼來做到這一點。無法在Android上的我的應用程序中打印日誌貓
Log.e("msg1","message1");
Log.e("msg2","message2");
Log.e("msg3","message3");
try {
String separator = System.getProperty("line.separator");
try {
Process mProcess = Runtime.getRuntime().exec("logcat -e");
BufferedReader reader = new BufferedReader(new InputStreamReader(mProcess.getInputStream()));
StringBuilder builder = new StringBuilder();
String line = "";
while ((line = reader.readLine())!= null) {
builder.append(line);
builder.append(separator);
}
System.out.println(separator +"OUTPUT - "+builder.toString());
tv.setText(builder.toString());
} catch (IOException e) { }
,並在清單文件本人同意,如:
<uses-permission android:name="android.permission.READ_LOGS" />
我無法從LOCAT文本視圖的信息。 這裏是代碼的在eclipse logcat的輸出:
09-18 11:01:51.649: INFO/ActivityManager(66): Displayed activity com.log.cat/.main1: 2224 ms (total 2224 ms)
09-18 11:01:52.799: INFO/ActivityManager(66): Starting activity: Intent { cmp=com.log.cat/.main (has extras) }
09-18 11:01:52.958: ERROR/msg1(346): message1
09-18 11:01:52.958: ERROR/msg2(346): message2
09-18 11:01:52.969: ERROR/msg3(346): message3
09-18 11:01:53.028: INFO/global(346): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
09-18 11:01:53.059: INFO/System.out(346): OUTPUT -
09-18 11:01:53.588: INFO/ActivityManager(66): Displayed activity com.log.cat/.main: 754 ms (total 754 ms)
所述的System.out。不會在logcat中打印任何東西。如果我使用logcat -d而不是logcat -e。它打印所有系統相關的信息,因爲沒有我的logcat信息。請幫幫我。我需要在textview中顯示我的應用程序logcat信息,而不是其他信息,以便我使用logcat -e。請幫幫我。
檢查我的答案 – Dharmendra
請看到我的編輯問題。 http://stackoverflow.com/questions/7213999/could-not-print-log-cat-in-my-app-on-android –