Android Wear – код для программного и непрерывного чтения результатов LogCat не работаетAndroid

Форум для тех, кто программирует под Android
Anonymous
Android Wear – код для программного и непрерывного чтения результатов LogCat не работает

Сообщение Anonymous »


Hi everyone I recently wrote some code to read LogCat output continuously within a background Thread started by a background Service in my app. I do not think there are errors in my code but it's not working.

In my Thread, I have:

@Override public void run() { Process process = null; String cmd = "logcat -v time | grep 'AudioFocus requestAudioFocus()'"; try { process = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(process.getOutputStream()); os.writeBytes("logcat -c" + "\n"); os.writeBytes(cmd + "\n"); os.flush(); } catch(Exception e) { } BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; try { while ( (line = reader.readLine()) != null ) { Log.e(StaticVal.TAG, line); // code for write line to my own log file } } catch(Exception e) { } } I also added permission to manifest:



However, when I plug my device with PC and test it with Android Studio, Log.e(StaticVal.TAG, line); did not print out the results and nothing wrote into my own log file.

Any help is appreciated!

(Directly run logcat -v time | grep 'AudioFocus requestAudioFocus()' on my device through adb terminal get the results as expected)


Источник: https://stackoverflow.com/questions/333 ... ously-is-n

Вернуться в «Android»