我见过其他解决方案,但似乎都不适用。
我正在尝试从执行“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.
关于java - 无法打开日志设备 '/dev/log/main' : Permission denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22028729/