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

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;
	}
	

方法的参数是你要ping的目标地址。

你可能感兴趣的:(UI,String)