ping方法判断网络是否可用
<pre><code>使用ping方法判断网络是否可用
private boolean startPing(String ip) {
Log.e(&quot;Ping&quot;, &quot;startPing...&quot;);
boolean success = false;
Process p = null;
try {
p = Runtime.getRuntime().exec(&quot;ping -n 1 -i 0.2 -W 1 &quot; + ip);
int status = p.waitFor();
if (status == 0) {
success = true;
} else {
success = false;
}
} catch (IOException e) {
success = false;
} catch (InterruptedException e) {
success = false;
} finally {
p.destroy();
}
return success;
}</code></pre>