java - 无法打开日志设备 '/dev/log/main' : Permission denied

标签 java android logging logcat processbuilder

我见过其他解决方案,但似乎都不适用。

我正在尝试从执行“logcat -d”的进程中读取数据,但我收到了标题中的错误。

我的 AndroidManifest.xml 包括:

<uses-permission android:name="android.permission.READ_LOGS" />

使用 adb shell,我可以很好地执行命令。

这是一个代码 fragment :

            ProcessBuilder procBuilder = new ProcessBuilder();
            procBuilder.redirectErrorStream(true);
            procBuilder.command("logcat", "-d");
            procBuilder.directory(new File("/"));
            Process process = procBuilder.start();
            //Process process = Runtime.getRuntime().exec("logcat -d");

            process.waitFor();

            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            StringBuilder log = new StringBuilder();
            String line = "";
            while ((line = bufferedReader.readLine()) != null) {
                log.append(line + "\n");
            }

执行时,我看到第一行是标题中的错误,仅此而已。

我在网上读到,没有 su 就无法执行 logcat,但是有很多这样的代码文章......工作得很好。

我可能做错了什么或可以尝试什么其他想法?

最佳答案

它被归类为前 10 个不良权限并在 jellybean 中关闭,来自 google 的答案:

Dan Galpin: Read system log. Now, I've got bad news for you guys. If you haven't watched some of our other presentations, read system log actually is gone as of J. There is no more read system log that you can get. However allows you, without a permission, to read the system log for your own app. So the good news is no creepy spying on what the user is doing by turning on their read system log permission. And at the same time you can still get to the useful logs you need to help your debugging if the crash recording and all the stuff we have on Google Play isn't enough.

引用号:http://youtu.be/WDDgoxvQsrQ?t=22m3s

关于java - 无法打开日志设备 '/dev/log/main' : Permission denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22028729/

相关文章:

java - 如何在执行作业时将 OracleDriver 添加到 hadoop 类路径?

android - 如何将时间戳字符串转换为毫秒?

node.js - 在 NodeJs 中将日志消息分成不同的颜色

logging - 如何使用 Quarkus 拦截日志消息以进行测试

logging - 堆栈跟踪作为字符串

Java Web 应用程序同步问题

java - Java JVM加载失败如何排查?

java - 用于指纹匹配的开源SDK

java - 如何在 android Jelly Bean Launcher 中添加自定义 View

java - android studio 生成Javadoc失败