Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not all data shown when Android logcat is read programatically

Tags:

android

logcat

I have such a problem, I try to get data from logcat programatically. permission has also been added to manifest file:

<uses-permission android:name="android.permission.READ_LOGS"/>

Code:

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Process process = Runtime.getRuntime().exec("logcat ActivityManager:I *:S");
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));

                String line;
                while ((line = bufferedReader.readLine()) != null) {
                    reactOnString(line);
                }
            } catch (IOException e) {
            }
        }
    }).start();

However I cannot see when other apps are launched. I am waiting for strings like the one below but they do not appear.

2260-2566/system_process                 I/ActivityManager: Start proc com.android.email for activity com.android.email/.activity.MessageCompose: pid=6460 uid=10011 gids={50011, 3003, 1015, 1023, 1028}

P.S. This code is run in service.

like image 835
Ruzard Avatar asked May 28 '13 15:05

Ruzard


People also ask

How do I read Logcat logs?

View your app logs Build and run your app on a device. Click View > Tool Windows > Logcat (or click Logcat in the tool window bar).

Why is Logcat empty?

There were two emulator entries in the logcat dropdown and it was connected to the wrong one. All I had to do was switch to the other one. I prevented the problem permanently by renaming the emulator.

Why is my Logcat empty Android Studio?

Go to the File option > click on “INVALIDATE CACHES/RESTART” then a dialog box will pop up, Select the “INVALIDATE CACHES/RESTART” button. This will automatically restart and build the index of android studio.

How do I stop Logcat from clearing?

Prevent clearing the log when the app crashes By default when the app got crashed the logcat clear's in the android studio. To prevent this, click the right end chooser(Filter Configuration chooser) in the logcat tab then select Edit Filter Configuration option and enter current app name and package name.


2 Answers

I have bad news for you: as of JB, READ_LOGS don't just work as it did anymore:

https://groups.google.com/forum/?fromgroups#!topic/android-developers/6U4A5irWang

(scroll to the post of Dianne Hackborn, an Android Develper) and this video:

Google I/O 2012 - Ten Things Game Developers Should Know

(22:47) for official sources.

However his has not been yet documented (the READ_LOGS permission doesn't report this) and is yet a source of confusion. You can only access your own logs now, and the good news is, you don't need to request permissions for it anymore (if your are targetting Jelly Beans, that's it...).

I guess it's a compromise the Android Dev team took to prevent malicious app from spying on the user, perhaps getting sensitive information (I wouldn't bet every app developer cleans it's own Log.d statements before release).

Hope this helps

like image 118
Rick77 Avatar answered Nov 11 '22 07:11

Rick77


From Android Jelly Bean, applications cannot read log entries from other applications, unless your device is rooted and you read the logs as superuser.

So basically... This is the expected behavior.

I could not find any official statement in the Android documentation (someone can edit this answer if they do), but you might be interested in having a look at this answer: https://android.stackexchange.com/questions/28857/how-can-i-access-android-log-files-on-my-nexus-7-without-root-access

like image 27
personne3000 Avatar answered Nov 11 '22 08:11

personne3000