当前位置:操作系统 > 安卓/Android >>

问题小结(10)-android中ping命令的实现

[java]
public static String pingHost(String str){ 
        String resault=""; 
        try { 
            // TODO: Hardcoded for now, make it UI configurable  
            Process p = Runtime.getRuntime().exec("ping -c 1 -w 100 " +str); 
            int status = p.waitFor(); 
            if (status == 0) { 
        //  mTextView.setText("success") ;  
                resault="success"; 
            }    
            else 
            { 
                resault="faild"; 
        //  mTextView.setText("fail");  
            } 
            } catch (IOException e) { 
        //  mTextView.setText("Fail: IOException"+"\n");  
            } catch (InterruptedException e) { 
        //  mTextView.setText("Fail: InterruptedException"+"\n");  
            } 
         
        return resault; 
    } 
     
作者:agods
补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,