0
我嘗試讀取我應用中的所有android logcat記錄並將它們顯示在列表視圖中。 在我的代碼有時我可以閱讀日誌,但somtimes不能。 如果我打開logcatactivity我可以讀取所有的日誌,但然後我不能讀android logcat不會每次都讀取日誌
oReadLogTask = new ReadLogTask();
oReadLogTask.execute();
private class ReadLogTask extends AsyncTask<Integer, Integer, Boolean>
{
private ProgressDialog oProgressDialog;
@Override
protected void onPreExecute()
{
oLogVeriler = new ArrayList<LogCatVeri>();
oProgressDialog = ProgressDialog.show(LogCat.this, "", "Log loading...");
oProgressDialog.show();
oProgressDialog.setCancelable(true);
oProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener()
{
public void onCancel(DialogInterface dialog)
{
oSayfaYukleTask.cancel(true);
}
});
}
protected void onProgressUpdate(Integer... progUpdate)
{
oProgressDialog.setMessage("Log load... " + progUpdate[0] + "/" + progUpdate[1]);
}
@Override
protected Boolean doInBackground(Integer... params)
{
if (params == null)
{
return false;
}
try
{
List<String> progs = new ArrayList<String>();
progs.add("logcat");
progs.add("-v");
progs.add("time");
progs.add("*:" + "V");
logcatProc = Runtime.getRuntime().exec(progs.toArray(new String[0]));
mReader = new BufferedReader(new InputStreamReader(logcatProc.getInputStream()), 1024);
int LineAdetTum = 0;
int LineAdetAranan = 0;
String LogTagAdKucuk = LogTagAd.toLowerCase();
String line;
while ((line = mReader.readLine()) != null)
{
LineAdetTum++;
publishProgress(LineAdetAranan, LineAdetTum);
if (!line.toLowerCase().contains(LogTagAdKucuk))
{
boolean ready = mReader.ready();
if (!ready)
break;
else
continue;
}
else
{
boolean ready = mReader.ready();
if (!ready)
break;
}
LineAdetAranan++;
publishProgress(LineAdetAranan, LineAdetTum);
LogCatVeri oLogVeri = new LogCatVeri(line, LogTagAdKucuk, LogTagAd);
oLogVeriler.add(oLogVeri);
}
return true;
}
catch (IOException ex)
{
Log.e("alogcat", "Log read err" + ex.getMessage(), ex);
return false;
}
catch (Exception ex)
{
Log.e("alogcat", "Log read err2" + ex.getMessage(), ex);
return false;
}
finally
{
if (logcatProc != null)
{
logcatProc.destroy();
logcatProc = null;
}
if (mReader != null)
{
try
{
mReader.close();
mReader = null;
}
catch (IOException e)
{
Log.e("alogcat", "Stream err", e);
}
}
}
}
@Override
protected void onPostExecute(Boolean result)
{
if (result)
ShowRes();
else
Toast.makeText(getApplicationContext(), "Log rec err", Toast.LENGTH_LONG).show();
oProgressDialog.dismiss();
}
@Override
protected void onCancelled(Boolean result)
{
super.onCancelled(result);
Toast.makeText(getApplicationContext(), "cancel", Toast.LENGTH_LONG).show();
}
}
public void ShowRes()
{
mLogEntryAdapter = new LogCatAdapter(this, R.layout.lc_log_cat_list, oLogVeriler);
mLogList.setAdapter(mLogEntryAdapter);
}
有沒有重播? –