I used NSDServiceInfo.getHost (). getHostAddress () output is the IPv4 to IPv6 device and router. for the device, I can already IPV4 so I need IPv6. as well as to the router, I can already so I need IPV4 IPV6.
The solution I have tried. but when his hostaddress issued IPV4, then exit the error "Not an IPv6 address: [xx, xx, xx, xx]
Meanwhile, when it issued hostaddress IPv6, then the error message "java.net.Inet6Address can not be cast to java.net.Inet4Address"
I like this coding
List <NSDServiceInfo> Data = new ArrayList<>();
InetAddress hostInet =InetAddress.getByName(Data.get(position).getHost().GetHostAddress());
byte [] addressBytes = hostInet.getAddress();
Inet6Address dest6 = Inet6Address.getByAddress(Data.get(position).getHost().GetHostAddress(), addressBytes, NetworkInterface.getByInetAddress(hostInet));
Inet4Address dest4 = (Inet4Address) Inet4Address.getByAddress (Data.get(position).getHost().GetHostAddress(), addressBytes);
Log.d ( "IP", "IPv4" + dest4.getHostAddress ());
Log.d ( "IP", "IPv6:" + dest6.getHostAddress ());