为什么这些日志过滤器需要花费很多时间才能在Android中的textview中显示结果?

时间:2017-03-12 17:27:05

标签: android logcat

我想只显示我的TAG登录文本视图
我正在使用这些过滤器,但在textview中显示日志需要花费很多时间。

我使用了这些过滤器

logcat TAG:V *:S  
logcat | find TAG  
logcat | grep TAG  
logcat TAG:* *:s

以下是我的代码..

public class LogsUtil {

    private static final String TAG = LogsUtil.class.getCanonicalName();
    private static final String processId = Integer.toString(android.os.Process.myPid());

    public static StringBuilder readLogs() {

        StringBuilder logBuilder = new StringBuilder();
        try {
            Process process = Runtime.getRuntime().exec("logcat TAG:V *:S");
            BufferedReader bufferedReader = new BufferedReader(
                    new InputStreamReader(process.getInputStream()));

            String line;
            while ((line = bufferedReader.readLine()) != null) {
                logBuilder.append(line + "\n");

             //   Log.i("LogUtil Sujeet",logBuilder.toString());
            }
        } catch (IOException e) {
            Log.e(TAG, "getLog failed", e);
        }
        return logBuilder;
    }
}

在mainactivity中解析textview中的logcat ..

MainActivity

public class MainActivity extends AppCompatActivity {
TextView tv:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

   tv = (TextView)findViewById(R.id.title);

    StringBuilder result = LogsUtil.readLogs();
    tv.setText(result.toString());

}

}

0 个答案:

没有答案