1

In my android test project, I simply read the logcat using adb command

like,

public StringBuilder log=new StringBuilder();
    public String line="";
    public String temp="";

public void testSolo() throws Exception {

             String baseCommand = "logcat -v time";
            baseCommand += " ActivityManager:I "; // Info for my app
            baseCommand += " *:S "; // Silence others

            try {
                  Process logReaderProcess = Runtime.getRuntime().exec(baseCommand);
                  BufferedReader bufferedReader = new BufferedReader(
                   new InputStreamReader(logReaderProcess.getInputStream()));

                   while ((line =bufferedReader.readLine()) != null) {
                            log.append(line); // here readLine() returns null
                          }

            }
            catch (IOException e1) {
                      // TODO Auto-generated catch block
                      e1.printStackTrace();
                    }

 }

but, here in string line I always get null value,

while the same thing always run in the android activity's onCreate() . I don't understand why this happen?

Same thing runs in activity class and not in the android test project.

I also add use -permission for READ_LOGS and WRITE_EXTERNAL_STORAGE in test project's manifest.xml file.

Is there anybody knows how it works or what happens?

Thanks in advance.

user370305
  • 108,599
  • 23
  • 164
  • 151
  • Don't you want the output stream? – K-ballo Oct 07 '11 at 06:23
  • Do you mean you're not managing to log anything? I strongly suggest that you put a logging statement in your exception handler... – Jon Skeet Oct 07 '11 at 08:36
  • @Jon Skeet - Thanks for your reply, I am getting the values from the logcat. using the above command, now when the same things If I put in android activity it gives me whole values from logcat Tag by ActivityManager and the same thing returns null values in android test project. I don't understand what happen. – user370305 Oct 07 '11 at 09:14
  • @user370305: Perhaps logcat simply doesn't work in test projects? Perhaps there are other ways of getting log information in tests? – Jon Skeet Oct 07 '11 at 09:18
  • @Jon Skeet - I don't know whether other ways are available or not, I also noticed the things happen only for logcat. But we can print the log message from the test project then why we can't access for read? – user370305 Oct 07 '11 at 09:34
  • @user370305: I don't know - but I'd expect there to be something about diagnostics in the documentation... – Jon Skeet Oct 07 '11 at 09:38
  • @Jon Skeet - ok, Thanks for your valuable time given to me. Now, I am try different things to get the log in the test project. Thanks once again. – user370305 Oct 07 '11 at 09:41

2 Answers2

0

Try to add

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

to your manifest.

savemaxim
  • 377
  • 3
  • 6
-1
String []baseCommand = new String[]{"logcat", "-v","time"}; 
Process logReaderProcess = Runtime.getRuntime().exec(baseCommand);

try this out

jazz
  • 1,216
  • 7
  • 7