Android在TextView中显示Logcat [英] Android display Logcat in TextView
本文介绍了Android在TextView中显示Logcat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在构建的应用具有对Android的超级用户访问权限.我希望在其中一个TextView中显示Logcat日志信息,以便在调试时可以将其显示在屏幕上.
The app I'm building have root-access to Android. I wish to show Logcat log information in one of the TextView so it can show up on the screen while i'm debugging.
有人可以给我一些想法,我可以调用哪些库/函数来访问这些日志吗?
Can someone give me some ideas which library/function i can call to access those log?
谢谢
推荐答案
这是一个博客完全按照您的要求执行.它具有有关如何显示Logcat日志内容的完整代码示例.这是代码:
Here's a blogpost that does exactly what you need it to do. It has a complete code example on how to display the contents of the Logcat log. Here's the code:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
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) {
// Handle Exception
}
}
}
Just to clarify, this is not my answer, here is the original
这篇关于Android在TextView中显示Logcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文