android 实时获取系统log

这里就直接写一个方法把,直接拿去用把 ,信息在线程里面


package com.cdl.util;

import android.util.Log;

import java.io.DataInputStream;

public class GetLogThread implements Runnable {

    StringBuffer logContent;

    public GetLogThread() {
        logContent = new StringBuffer();
    }

    @Override
    public void run() {
       
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 + "\n");
        Log.e("HAHA", "========line===" + line);
    }
    Log.e("HAHA", "========打印得log===" + log);
} catch (IOException e) {
    Log.e("HAHA", "========读取log异常===" + e.toString());
}
}}

你可能感兴趣的:(安卓前端,java,android)