kande
kande

Reputation: 559

Execute logcat with tag on Android returns empy

I have an Activity which every second write a counter to the logcat:

Runnable rLog = new Runnable() {

    @Override
    public void run() {
        i++;
        Log.d("bbb", "i= " + i);
        handler.postDelayed(this, 1000);                
    }
}; 

In addition - I have a service which read from "logcat -s bbb" and log it:

Runnable rGetLog = new Runnable() {

    @Override
    public void run() {
        Runtime rt = Runtime.getRuntime();
        Process process = null;
        try {
            process = rt.exec("logcat -s bbb");
        } catch (IOException e1) {
            e1.printStackTrace();
        }

        BufferedReader bufferedReader = 
                new BufferedReader(new InputStreamReader(process.getInputStream()));

        try {
            while ((line = bufferedReader.readLine()) != null)
            {
                Log.d("aaa", "get line = " + line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }               
    }
};  

This code works well. The problem starts when I change the tag "bbb" to a real tag such as "AndroidRuntime" or another tag... I got an empty response from logcat (if I run at the same time "logcat -s AndroidRuntime" from adb I got lots of lines...)

Who knows what the problem is? what can be different?

Thanks!

Upvotes: 0

Views: 69

Answers (1)

Wops
Wops

Reputation: 993

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

try using sudo to get permissions: process = rt.exec("su && logcat -s YOUR_TAG");

Upvotes: 1

Related Questions