デバイス上のすべてのログを読み取るアプリを作成しようとしています。クライアント/サービス アーキテクチャがあり、クライアント プロセスとサービス プロセスの両方からのログ メッセージが表示されますが、電話の他のアプリケーションからのメッセージは表示されません (デスクトップの logcat を使用すると、他のメッセージが表示されます)。
ルートは必要ですか?
コード スニペット
マニフェスト
<uses-permission android:name="android.permission.READ_LOGS" />
ログリーダー
Runtime.getRuntime().exec("logcat -c").waitFor();
Process process = Runtime.getRuntime().exec("logcat -v long *:*");
BufferedReader reader =
new BufferedReader(new InputStreamReader(process.getInputStream()));
while (true) {
String nextLine = reader.readLine();
if (!nextLine.contains("LogWatcher-D")) {
Log.w("LogWatcher-D", "See: " + nextLine);
}
// Process line
}