gpt4 book ai didi

android - 如何在我的设备上获取 logcat 以显示来自所有进程的日志

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:01:28 28 4
gpt4 key购买 nike

我正在尝试编写一个应用程序来读取我设备上的所有日志。我有一个客户端/服务架构,我看到来自客户端和服务进程的日志消息,但我没有看到来自手机上任何其他应用程序的任何消息(我确实看到使用桌面 logcat 的其他消息)。

我需要root吗?

代码 fragment

list

<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
}

最佳答案

在 Android 4.1+ 上,您只能访问进程记录的日志消息,除非您拥有 READ_LOGS 权限。该权限要求您的应用使用与设备固件签名相同的签名 key 进行签名,或者您的应用安装在系统分区上。

关于android - 如何在我的设备上获取 logcat 以显示来自所有进程的日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16222766/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com