JmDNS doesn't work properly on android 4.1

自古美人都是妖i 提交于 2019-12-03 00:44:45

Solved:

I partially followed the advice here but instead of create(String hostName) I did create(InetAddress addr).

String ip = Formatter.formatIpAddress(wifiManager.getConnectionInfo().getIpAddress());
_bindingAddress = InetAddress.getByName(ip);
_jmdns.create(_bindingAddress);

I'm pretty sure the following code is working on my phone(android 4.1), for anyone else reference~

WifiManager wifi=(WifiManager)getSystemService(android.content.Context.WIFI_SERVICE);

WifiInfo wifiinfo = wifi.getConnectionInfo();
int intaddr = wifiinfo.getIpAddress();

byte[] byteaddr = new byte[] { (byte) (intaddr & 0xff), (byte) (intaddr >> 8 & 0xff), (byte) (intaddr >> 16 & 0xff), (byte) (intaddr >> 24 & 0xff) };
InetAddress addr=InetAddress.getByAddress(byteaddr); //Need to process UnknownHostException

jmdns=JmDNS.create(addr);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!