为什么进程在测试运行器类中给出空输入流?
在我的 android 测试项目中,我只是使用 adb 命令
读取 logcat
,
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();
}
}
但是,在 string line
中我总是得到 null value,
而同样的事情总是在 android activity 的 onCreate()
中运行。 我不明白为什么会出现这种情况?
同样的事情在活动类中运行,而不是在 android 测试项目中运行。
我还在测试项目中添加了 READ_LOGS
和 WRITE_EXTERNAL_STORAGE
的 use -permission manifest.xml
文件。
有人知道它是如何工作的或者会发生什么吗?
提前致谢。
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'smanifest.xml
file.
Is there anybody knows how it works or what happens?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试添加
到您的清单中。
Try to add
to your manifest.
试试这个
try this out