问题
JmDNS
I am implementing JmDNS as follows here. When running the code on my android 2.3.5 htc Evo I am able to discover my linux computer. However, when i run the same code on my samsung galaxy s3 (4.1.0) nothing shows up. What is strange is that it was working on my 4.1 a week ago and now it isn't. I have tried someone else's solution here but no luck. If any one has experienced this and could shed some light on why gingerbread is working with jmdns but not jellybean.
Clarification:
My android 4.1 device will not resolve any services except for those that are created from the device. My 2.3 device will resolve services except those created from the 4.1 device. could it be ip6 to ip4?
回答1:
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);
回答2:
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);
来源:https://stackoverflow.com/questions/13677199/jmdns-doesnt-work-properly-on-android-4-1