Ping在android中

时间:2014-09-08 13:52:26

标签: android if-statement android-studio ping

我在stackoverflow中看到了这个,我找到了很多结果,但这些答案中的任何一个都适用于我

但其中一个代码适用于%50

public void GET3() {
    TextView SYS3;

    String ip = "www.codelow-dat.site90.com";
    String pingResult = "";
    String pingCmd = "ping" + ip;

    Runtime r = Runtime.getRuntime();
    Process p = null;
    try {
        p = r.exec(new String[]{"ping", "-c 4", "www.codelow-dat.site90.com"});
    } catch (IOException e) {
        e.printStackTrace();
    }
    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String inputLine;
    SYS3 = (TextView) findViewById(R.id.SYS3);
    SYS3.setText(getString(R.string.goingloop)); //going loop
    try {
        while ((inputLine = in.readLine()) != null) {
            pingResult = inputLine;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    SYS3 = (TextView) findViewById(R.id.SYS3);
    SYS3.setTextColor(Color.parseColor("#66CD00"));
    if (Boolean.valueOf(pingResult) == null) {
        SYS3.setTextColor(Color.parseColor("#D61D00"));
        SYS3.setText(getString(R.string.somethingwrong)); //something is wrong
    } else {
        SYS3.setText(pingResult + getString(R.string.IsOk)); //, is OK
    }
    try {
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

“if”无论如何都不起作用我尝试了一些但不起作用。当ping错误时,只能找到字符串IsOk(,可以)而不是字符串somethingwrong(出错)(并将文本颜色更改为红色)

全部谢谢

0 个答案:

没有答案