2017-04-27 7 views
0

모든 프로세스에 대해 LogCat 메시지를 읽을 수 있습니까?Android LogCat 프로그래밍 방식 - 모든 프로세스

File filename = new File(Environment.getExternalStorageDirectory() + "/mylog.txt"); 
    if (filename.exists()) { 
     filename.delete(); 
    } 

    String cmd = "logcat -f " + filename.getAbsolutePath(); 
    Runtime.getRuntime().exec(cmd); 

단지 내 응용 프로그램에 연결 로그를 기록합니다 :

(우리는 '더 필터'옵션을 선택하지 않는 경우 안드로이드 스튜디오에서처럼) 나는이 실행합니다.

답변

0

android 버전 4.1 이상에서는 다른 응용 프로그램의 logcat을 더 이상 읽을 수 없습니다. 참조 용으로 this을 참조하십시오.

버전 당신은 <uses-permission android:name="android.permission.READ_LOGS" /> 권한을 부여 할 필요가보다 낮은 4.1

Runtime.getRuntime().exec("logcat -c").waitFor(); 
Process process = Runtime.getRuntime().exec("logcat -v long *:*"); 
BufferedReader reader = 
new BufferedReader(new InputStreamReader(process.getInputStream())); 
while (true) { 
    String nextLine = reader.readLine(); 
    if (!nextLine.contains("LogWatcher-D")) { 
     Log.w("LogWatcher-D", "See: " + nextLine); 
    } 
} 

에 대한 다른 응용 프로그램의 로그를 읽을 수 있습니다.

Reference

명확한 아이디어를 얻으려면, 당신은 참조 할 수 있습니다 this