why process give null inputstream in test runner class?

≡放荡痞女 提交于 2019-12-24 10:00:35

问题


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.


回答1:


Try to add

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

to your manifest.




回答2:


String []baseCommand = new String[]{"logcat", "-v","time"}; 
Process logReaderProcess = Runtime.getRuntime().exec(baseCommand);

try this out



来源:https://stackoverflow.com/questions/7683642/why-process-give-null-inputstream-in-test-runner-class

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