Android, Logcat and BufferedReader - no logs

99封情书 提交于 2019-12-02 08:58:08

问题


I'm making an application, which must show me in logs which applications I start on device. I use logcat ActivityManager:I *:S and it doing this well.. at some devices and emulators.

But at some devices it has strange behavior - everything I see in log is repetition of:

02-18 16:32:09.132: D/LockApp(4082): --------- beginning of /dev/log/main

Code snippet:

Process process = null;
try {
    process = Runtime.getRuntime().exec("logcat -c");
    process = null;
    process = Runtime.getRuntime().exec("logcat ActivityManager:I *:S");
    br = new BufferedReader(new InputStreamReader(process.getInputStream()));
    String line = null;

    line = br.readLine();

    while( line != null && !this.isInterrupted()){
        Log.d(Tag, "Start LockApp loop");
        Log.d(Tag, line);
    }
} catch (IOException e) {
    Log.d(Tag, e.toString());
}

And I have android.permission.READ_LOGS in Manifest

I`m doing it in Android 4.1 and 4.2


回答1:


What is this logcat -c> this will Clears (flushes) the entire log and exits.

There are only V,D,I,W,E & WTF :-) Six type of logcat category

change it to Runtime.getRuntime().exec("logcat -e"); Link here:

EDIT: There is an problem in Reading in jelly bean link here

READ_LOGS permission on Jelly Beans (Android 4.1) will not be granted anymore to normal apps.

Apps are only allow to read their own logs.

See for more information

You could try to implement a function to grant yourself READ_LOGS permission with for users with rooted devices.



来源:https://stackoverflow.com/questions/14932502/android-logcat-and-bufferedreader-no-logs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!