Android

个人Android学习总结


ping方法判断网络是否可用

<pre><code>使用ping方法判断网络是否可用 private boolean startPing(String ip) { Log.e(&amp;quot;Ping&amp;quot;, &amp;quot;startPing...&amp;quot;); boolean success = false; Process p = null; try { p = Runtime.getRuntime().exec(&amp;quot;ping -n 1 -i 0.2 -W 1 &amp;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>

页面列表

ITEM_HTML