How to read Logcat contents programmatically in Android?

By | July 16, 2011

This is an example to read Logcat contents programmatically in Android.
Normal developers won’t need this, but still it is a good thing to know how to do it.

package pack.coderzheaven;

import android.os.Bundle;
import android.widget.TextView;

public class ReadLogDemo extends Activity {
    public void onCreate(Bundle savedInstanceState) {
    	    try {
    	      Process process = Runtime.getRuntime().exec("logcat -d");
    	      BufferedReader bufferedReader = new BufferedReader(
    	      new InputStreamReader(process.getInputStream()));

    	      StringBuilder log=new StringBuilder();
    	      String line = "";
    	      while ((line = bufferedReader.readLine()) != null) {
    	      TextView tv = (TextView)findViewById(;
    	    } catch (IOException e) {
Read Logcat Demo

Read Logcat Demo

if you like the post then click on the plus button to share it with your friends and leave your valuable comments.

7 thoughts on “How to read Logcat contents programmatically in Android?

  1. murali

    I have run the sample application. it runs successfully. but i use “locat -e” option instead of “logcat -d”. it does not print anything in the text view. i requested you to add the solution for it.

    Thank you.

  2. Tauon

    Unfortunately, a cut and paste of this code does not work. The very first readLine() returns null and so it drops straight out the loop. I am guessing that because Murali got it working, there is something that needs to be done that has not been described in this post?

  3. Kontakthi

    Sorry,a bit late but I resolved the null return from the readLine() call by adding the following line to my manifest file:

    1. Arun Pandian

      If u r wondering, set your permission in android manifest xml page to


      Please let me your solutions

  4. Pingback: Android display Logcat in TextView - MicroEducate

Leave a Reply

Your email address will not be published. Required fields are marked *