问题
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