我已经搜索了,我发现下面的代码会让我的程序读取android中logcat的输出。但是,在我调用这个函数之后,没有任何反应。没有任何东西通过system.out输出,除了“logcat called” 。我真的不知道发生了什么,因为很多帖子在这里告诉这将工作:<为什么我不能在程序中读取logcat输出?
public void Collector_logcat(){
String stringbuffer="";
String command="logcat -d";
String command_c="logcat -c";
System.out.println("logcat called\n");
try{
m_logcatprocess=Runtime.getRuntime().exec(command);
m_logcat_inputreader=new InputStreamReader(m_logcatprocess.getInputStream());
m_logcat_reader=new BufferedReader(m_logcat_inputreader);
while((stringbuffer=m_logcat_reader.readLine())!=null){
System.out.println(stringbuffer+"\n");
}
Runtime.getRuntime().exec(command_c);
}
catch(Exception ex){
System.out.println(ex.getMessage());
System.out.println("error in Collector_logcat\n");
}
return ;
}
如果我尝试直接读取/ dev/log/main文件,它显示permis锡永被拒绝。我不希望我的程序获得root previlige – 2012-04-20 15:38:00
logcat在停止工作时是否出现错误? – dymmeh 2012-04-20 15:41:35
@dymmeh没有任何错误。唯一的输出是“logcat called”.... – 2012-04-20 15:44:28