0

I'm writting an app and there are a lot of LOG.d() statments to check the behavior of my code.

Now I want to write the result of all this LOG.d() statements in an listview to see them on my device when they appear.

Is there something like an log broadcast witch I can receive in my activity or do I have to add the logic for my listview log to all the places where LOG.d() is called again?

Or is there maybe an other way to achieve this?

2 Answers2

0

You can simply use Process to execute the logcat command on the device itself, and stream its output.

Process process = Runtime.getRuntime().exec("logcat -<flags>");
BufferedReader bufferedReader = new BufferedReader(
                    new InputStreamReader(process.getInputStream()));

String line;
while ((line = bufferedReader.readLine()) != null) {
    //code here
}
Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
0

Check Amit_android's answer in this question.

You can read the generated file and display it in your app.

Community
  • 1
  • 1
Sebastiandg7
  • 1,175
  • 1
  • 15
  • 22
  • I recommend you to execute the "logcat -c" command before start writting the logcat to the file so you you can have just your app's logs. Remmeber to add the required permissions: – Sebastiandg7 Jun 22 '16 at 17:58