1

他の投稿を読んでも、「トリック」がわかりません。

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 を使用しています。

ありがとう

4

2 に答える 2

6

エラー情報を取得するには、以下のコマンドを実行するだけで、自分でファイルを作成する必要はありません。

Runtime.getRuntime().exec("logcat -v time -r 100 -f /sdcard/log.txt *:E");

Logcat パラメーター オプション:

-r <size in kilobytes> -> for specifying the size of file  
-f <filename> -> file to which you want to write the logs.
于 2011-06-03T14:00:56.993 に答える
2

ArrayListなしで試してみてください。次の方法で実装したコマンドStringを渡すだけです(ArrayListなし)。わたしにはできる。

        String baseCommand = "logcat -v time";
        baseCommand += " MyApp:I "; // Info for my app
        baseCommand += " *:S "; // Silence others

        ServicesController.logReaderProcess = Runtime.getRuntime().exec(baseCommand);
于 2011-04-05T20:44:10.177 に答える