我阅读了其他帖子,无法弄清楚“诀窍”。
我查看了 Log Collector,但无法使用单独的 APK。我基本上使用相同的方法,并且我一直没有得到任何关于流程输入流的信息。
我在清单中有 READ_LOGS。
在我的默认活动中,我可以获取日志,但如果我将逻辑移动到另一个活动或使用异步任务,则不会返回任何输出。
此代码来自我的默认活动...内联,我将其转储到日志中
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);
}
Log.d(LOGTAG, "Logcat: " +log.toString());
} catch (IOException e) {}
如果我将它包装在 asynctask 中或只是将它内联到另一个活动中,它不会返回任何内容
ArrayList<String> commandLine = new ArrayList<String>();
//terminate on completion and suppress everything except the filter
commandLine.add("logcat -d -s");
...
//replace asynctask with inline (could not get log in asynctask)
showProgressDialog(getString(R.string.acquiring_log_progress_dialog_message));
final StringBuilder log = new StringBuilder();
BufferedReader bufferedReader = null;
try{
Process process = Runtime.getRuntime().exec(commandLine.toArray(new String[0]));
bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = bufferedReader.readLine()) != null){
log.append(line);
log.append(MangoApp.LINE_SEPARATOR);
}
sendIntent.putExtra(Intent.EXTRA_TEXT, log.toString());
startActivity(Intent.createChooser(sendIntent, getString(R.string.chooser_title)));
dismissProgressDialog();
dismissMainDialog();
finish();
}
catch (IOException e){
dismissProgressDialog();
showErrorDialog(getString(R.string.failed_to_get_log_message));
Log.e(LOGTAG, "Log collection failed: ", e);//$NON-NLS-1$
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException ignore) {}
}
}
任何人都可以发现差异或解释魔术吗?我很确定命令行在第二个版本中是正确的,所以我摸不着头脑。我在模拟器上使用 2.1 SDK 7。
谢谢