In an Android app executing the following piece of code to determine if a hostname is present in my network:
for (int i = 0; i < listOfHostnames.size(); i++) {
//noinspection unused
String hostname = listOfHostnames.get(i).getAddress();
try {
InetAddress test = InetAddress.getByName(listOfHostnames.get(i).getAddress());
//noinspection unused
String testHost1 = test.getHostAddress();
Logging.logw("Found", testHost1);
} catch (Exception e) {
Logging.logw(e.getClass() + " InetAddress EX", e.getMessage());
continue;
}
//.....
}
It works on most devices i tested, but it fails on a Samsung Galaxy Tab-A (SM-T550) with this following exception (hostname isn't that one):
W/class java.net.UnknownHostException InetAddress EX: Unable to resolve host "hostname-abc": No address associated with hostname
Do Samsungs need some extra code,or is there another way to check if a hostname is present on the network?
EDIT
listOfHostnames is a list of objects, where the getAddress method returns hostnames, such has "BrandT-12-28183" (the type of hostnames the devices using have)
I also have these permissions declared on the manifest:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />