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?
问题:
回答1:
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.
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)
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.
EDIT: 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)
回答2:
Yes you can. You just need a rooted device.