Read Logs from All Apps on Android from Within an App for Android 4.2+

Read logs from all apps on android from within an app for android 4.2+

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)

So how can I see the logs in Jelly Bean?

I got the answer in this google groups thread:
https://groups.google.com/forum/?fromgroups#!searchin/android-developers/READ_LOGS/android-developers/6U4A5irWang/8xOi74KfRIYJ

the message by Mark Murphy replying to Matteo Sisti Sette (which is me).

(it doesn't seem to be possible to link to a particular message, is it?)

POWER + VOLUME_UP + VOLUME_DOWN will generate a report and a screenshot that you can send via email or upload to Drive (ridiculous you can't share it in an arbitrary way such as send via bluetooth or open as text file, but anyways).

(seems you have to hold them for a while and the action is launched when you release them)

At first I thought he was making fun of me and that would just reboot or something, but then I tried and it works.

capture log of entire device within an application

To access all of LogCat, the app has to hold the READ_LOGS permission. Ordinary Android apps cannot hold this permission, as of Android 4.1 or 4.2. Only apps signed with the signing key that signed the firmware can hold this permission. In effect, that means that you can only hold this permission if you create your own custom Android ROM.

Android LogCat programmatically - all processes

From android version 4.1+ you cannot read logcat of other application anymore. See this for reference.

To read logs of other application for version lower than 4.1

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

You need to give <uses-permission android:name="android.permission.READ_LOGS" /> permission.

Reference

To get clear idea, you can refer this



Related Topics



Leave a reply



Submit