他の投稿を読んでも、「トリック」がわかりません。
Log Collector を見ましたが、個別の APK を使用できません。私は基本的に同じアプローチを使用していますが、プロセスの入力ストリームには一貫して何も返されません。
マニフェストに READ_LOGS があります。
デフォルトのアクティビティ内からログを取得できますが、ロジックを別のアクティビティに移動したり、asynctask を利用したりすると、出力が返されません。
このコードは私のデフォルトのアクティビティからのものです...インラインで、ログにダンプします
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番目のバージョンで正しいと確信しているので、頭を悩ませています。エミュレータで 2.1 SDK 7 を使用しています。
ありがとう