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 java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class ReadLogDemo extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); 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) { log.append(line); } TextView tv = (TextView)findViewById(R.id.textView1); tv.setText(log.toString()); } catch (IOException e) { } } }
if you like the post then click on the plus button to share it with your friends and leave your valuable comments.
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.
u need to add
in manifest file
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?
Sorry,a bit late but I resolved the null return from the readLine() call by adding the following line to my manifest file:
Hi,
If u r wondering, set your permission in android manifest xml page to
..
Please let me your solutions
No need to add any permissions.
Pingback: Android display Logcat in TextView - MicroEducate