通过执行ping命令并获取命令的返回值,代码如下: 123456789101112131415 public static boolean isNetPingUsable(){ Runtime runtime = Runtime.getRuntime(); try{ Process process = runtime.exec("ping -c 1 www.baidu.com"); int ret = process.waitFor(); if(ret == 0){ return true; }else{ return false; } }catch (Exception e){ e.printStackTrace(); } return false;} ret=0时:当前网络可用ret=1时:需要网页认证的wifiret=2时:当前网络不可用 赞微海报分享
近期评论