Is Android connected to your server : Connectivity « Network « Android






Is Android connected to your server

    
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

class FileUtils {

  public static boolean isConnection() {

    URL url = null;
    try {
      url = new URL("http://yourServer");
    } catch (MalformedURLException e) {
      e.printStackTrace();
    }
    URLConnection cn;
    InputStream stream = null;
    try {
      cn = url.openConnection();
      cn.connect();
      stream = cn.getInputStream();

      DataInputStream data = new DataInputStream(stream);

      if (data == null)
        return false;
      int code = data.readInt();
      if (code == 13) {
        return true;
      } else {
        return false;
      }
    } catch (IOException e) {
      return false;
    }
  }
}

   
    
    
    
  








Related examples in the same category

1.is Network Available
2.System InetAddress
3.is Net Connected
4.Connectivity Tester
5.Is connected
6.Is Connected To Internet