从 android 4.2+ 的应用程序中读取 android 上所有应用程序的日志 [英] Read logs from all apps on android from within an app for android 4.2+

查看:46
本文介绍了从 android 4.2+ 的应用程序中读取 android 上所有应用程序的日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信应用程序在 android post 4.2 中读取日志的方式已经发生了变化.但我想知道我是否可以从当前版本的 android 应用程序中读取所有日志,包括来自 logcat 的系统日志?如果是,是否需要一些许可?

I believe there have been changes to the ways apps can read logs in android post 4.2. But I wanted to know if I can read all the logs including system logs from logcat from within an app for current versions of android? If yes does it need some permission or not?

推荐答案

除非你 root 否则你不能这样做,因为 Jelly Bean.请参阅此 Android 错误报告 和此 相关讨论.引用:

Unless you rooted you cannot do this since Jelly Bean. See this Android bug report and this related discussion. Quote:

变化是第三方应用程序无法再读取日志权限,但是每个应用程序都可以读取仅包含的日志他们写的行,不需要任何许可.

The change is that third party applications can no longer get the read logs permission, however every app can read the logs containing only the lines they have written, without needing any permission.

请记住,对日志的访问从未成为 SDK 的一部分,并且仍然不是 SDK 的一部分.如果你当时依赖它,即使在此更改之后,您将面临将来崩溃的风险.(和这就是为什么这在文档中丢失的部分原因,它不是SDK,所以实际上没有一个地方可以记录它记录它会使它成为我们不知道的 SDK 的一部分想.:p)

Keep in mind that access to the logs has never been part of the SDK, and is still not part of the SDK. If you are relying on it then, even after this change, you run the risk of breaking in the future. (And that is partly why this got lost for documentation, it is not part of the SDK, so there isn't really a place to document it, in fact documenting it would kind-of make it a part of the SDK which we don't want. :p)

此外,我们真的很希望开发人员不要将其视为许可进一步滥用系统日志并喷出越来越多的东西从他们的应用程序进入它.日志噪声一直是一个持续的问题Android(不仅适用于第三方应用程序,我们总是难以交付没有太多噪音的开源平台),如果事情继续下去变得更糟,我们可能会进一步改变它以变得更好控制它.

Also we really really hope that developers don't take this as license to further abuse the system logs and spew increasing amounts of stuff into it from their app. Log noise has been a continual problem on Android (not just for third party apps, we always struggle to ship the open source platform without a lot of noise), and if things continue to get worse we will probably make further changes to it to better control it.

如果您可以访问设备,那么您可以查看那里的日志,甚至尝试向您的应用授予上述权限:

if you got access to the device, then you can peek logs there or even try to grant said permission to your app:

adb shell pm grant <pkg> android.permission.READ_LOGS

但在其他情况下,您不走运(除非您在框架中发现错误)

but for other cases you are out of luck (unless you find a bug in the framework)

这篇关于从 android 4.2+ 的应用程序中读取 android 上所有应用程序的日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆