开发者

could not print log cat in my app on android

i am doing an app for print log cat information in a text view . i use the following code to do that.

Log.e("msg1","message1");
Log.e("msg2","message2");
Log.e("msg3","message3");
try {
         String separator = System.getProperty("line.separator"); 
                 try {
                     Process mProcess = Runtime.getRuntime().exec("logcat -e");
                     BufferedReader reader =  new BufferedReader(new InputStreamReader(mProcess.开发者_高级运维getInputStream()));
                     StringBuilder builder = new StringBuilder();
                     String line = "";

                     while ((line = reader.readLine())!= null) {
                         builder.append(line);
                         builder.append(separator);
                     }
                     System.out.println(separator +"OUTPUT - "+builder.toString());
                     tv.setText(builder.toString());
    } catch (IOException e) { }

and in manifest file i give permission like:

      <uses-permission android:name="android.permission.READ_LOGS" />

i could not get no information from locat in the text view. here is the output of the code in the eclipse logcat:

09-18 11:01:51.649: INFO/ActivityManager(66): Displayed activity com.log.cat/.main1: 2224 ms (total 2224 ms)
09-18 11:01:52.799: INFO/ActivityManager(66): Starting activity: Intent { cmp=com.log.cat/.main (has extras) }
09-18 11:01:52.958: ERROR/msg1(346): message1
09-18 11:01:52.958: ERROR/msg2(346): message2
09-18 11:01:52.969: ERROR/msg3(346): message3
09-18 11:01:53.028: INFO/global(346): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
09-18 11:01:53.059: INFO/System.out(346): OUTPUT - 
09-18 11:01:53.588: INFO/ActivityManager(66): Displayed activity com.log.cat/.main: 754 ms (total 754 ms)

the system.out. does not print any thing in the logcat. if i use logcat -d instead of logcat -e . it print all system related information in that there is no my logcat information. please help me. i need to show my app logcat information in the textview not other informations so that i use logcat -e. please help me.


This is working code for me You are using Runtime.getRuntime().exec("logcat -e"); So it will give you if any error in process So if not any error in your execution it will not display any text in your textview

If you want to test your code change the value Runtime.getRuntime().exec("logcat -e"); to Runtime.getRuntime().exec("logcat -d");

You will get text in text view

There are V,D,I,W,E five type of logcat category

For more details see below link

Click here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜