Here you can find the source of isNetworkAvailable()
public static boolean isNetworkAvailable()
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; public class Main { /**//from w w w . j a v a2 s . c om * Short method to check whether or not the user has an active internet connection */ public static boolean isNetworkAvailable() { try { final URL url = new URL("http://www.google.com"); final URLConnection conn = url.openConnection(); conn.connect(); return true; } catch (MalformedURLException e) { throw new RuntimeException(e); } catch (IOException e) { return false; } } }