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