Android: Ping an external server from android device
// ping external servers public static final String PING_ONE = "ping -c 1 your server IP" ; public static final String PING_TWO = "ping -c 1 your server IP " ; try { Process p1 = java.lang.Runtime. getRuntime ().exec( PING_ONE ); int p1RetExitVal = p1.waitFor(); if (p1RetExitVal == 0 ) { // Internet available networkState = true ; } else { Process p2 = java.lang.Runtime. getRuntime ().exec( PING_TWO ); int p2RetExitVal = p2.waitFor(); if (p2RetExitVal == 0 ) { // Internet available networkState = true ; } } } catch (Exception e) { networkState = false ; e.printStackTrace(); }
Comments
Post a Comment