Androidでlogcatの情報を読み込む
2719 ワード
プログラム実行プロセスでいくつかの異常に遭遇する必要がある場合があります.logcatの情報を収集する必要があります.androidでは、次の方法で取得できます.
private static String getLogcatInfo(){
String strLogcatInfo = "";
try{
ArrayList<String> commandLine = new ArrayList<String>();
commandLine.add("logcat");
commandLine.add( "-d");
commandLine.add("*:E"); //
ArrayList<String> clearLog = new ArrayList<String>(); // logcat -c
clearLog.add("logcat");
clearLog.add("-c");
Process process = Runtime.getRuntime().exec(commandLine.toArray(new String[commandLine.size()]));
BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(process.getInputStream()));
String line = null;
while ((line = bufferedReader.readLine()) != null) {
Runtime.getRuntime().exec(clearLog.toArray(new String[clearLog.size()]));
strLogcatInfo = strLogcatInfo + line + "
";
}
bufferedReader.close();
}
catch(Exception ex)
{
process.destroy();
}
return strLogcatInfo;
}