So, I'm trying to send POST requests to an IP adress, but I've found a problem way before that. To check if there's a working connection to the internet I have the following method called when creating the Activity:
public void checkInternectConnection() {
AsyncTask.execute(() -> {
try {
InetAddress inAddress = InetAddress.getByName("https://google.com");
if (inAddress.equals("")) {
networkAvilable = true;
} else {
networkAvilable = false;
}
} catch (Exception e) {
e.printStackTrace();
networkAvilable = false;
}
});
}
When this code is executed, it always catches the exception java.net.UnkonwnHostException: Unable to resolve host "https://google.com": No address associated with hostname.
I've serched the error and all I can find is that the app doasn't have Internet permissions, but I have in the android manifest that permission already ( <uses-permission android:name="android.permission.INTERNET" />)
I've also tried with http://google.com instead of https, but nothing works.
Any ideas?
InetAddress.getByName()takes a hostname, and the protocol (http://) is not part of the hostname. Check Muhammad's answer.