I need to save the logcat output when i get an ANR error to a string variable, and display it on a text view inside my application. I have tried to do so by calling this function on button press
Process process = Runtime.getRuntime().exec("logcat -d | grep \"ANR\" -A 38");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
StringBuilder log = new StringBuilder();
String line = "";
while ((line = bufferedReader.readLine()) != null) {
log.append(line);
}
mTxtAnrinfo.setText(log.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
but it does not seem to work. Worse is debug isnt giving helpful information. I have also set the required manifest file permissions
<uses-permission android:name="android.permission.READ_LOGS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
What is it i am missing? just executing the command logcat -d | grep "ANR" -A 38 gives the required logcat data inside the shell, but when i run it from within the app, i get nothing. The lines in the while loop are null.
Thanks!
UPDATE: The app is installed as a system app, and the logs to be read are from other apps that encounter the ANR error.