2
I need to make a test connection with the web server, I am using this code below but all the attempts I made it always fall in the catch
HttpURLConnection conn = null;
try {
URL url = new URL("https://www.google.com");
conn = (HttpURLConnection) url.openConnection();
if (conn.getResponseCode() == conn.HTTP_OK) {
Toast.makeText(getApplicationContext(), "Conexao ok" ,Toast.LENGTH_LONG).show();
return false;
} else {
Toast.makeText(getApplicationContext(), "Conexao Problema", Toast.LENGTH_LONG).show();
return false;
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Falha:" + e.getMessage() ,Toast.LENGTH_LONG).show();
return false;
} finally {
if (conn != null) {
Toast.makeText(getApplicationContext(), "Disconnect" ,Toast.LENGTH_LONG).show();
conn.disconnect();
}
}
No catch which message it returns?
– Amadeu Antunes