I am developing in Android , and I want to get the IP address via domain name.
I have a WiFi device , the WiFi device join to the WiFi network same as my computer.
And the domain name of WiFi device is "abc.local" , I can ping "abc.local" success via my computer.
But It got the java.net.UnknownHostException: Unable to resolve host "abc.local": No address associated with hostname
when I use the following code in Android, .
new Thread(new Runnable() {
@Override
public void run() {
try {
InetAddress address = InetAddress.getByName("abc.local");
}
catch(Exception e) {
Log.d(TAG,"mConnectionMode error = " + e);
}
}
}).start();
I also add the following permission in AndroidMainifest.xml
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Why the Android device can not get the ip Address via domain name ?
Thanks in advance.