How can I discover zeroconf (Bonjour) services on Android? I'm having trouble with jmDNS

后端 未结 5 754
臣服心动
臣服心动 2020-11-30 18:42

I\'m working with a Droid / Android 2.0.1 and encountering an issue apparently many people have: I\'m unable to discover services using the one pure-Java zeroconf library I

5条回答
  •  萌比男神i
    2020-11-30 18:57

    I'm new as well otherwise I would have just left a comment on smountcastle's answer which is mostly correct. I have just been dealing with the exact same issue on a Droid running Android 2.1. I found that I needed to set the MulticastLock to reference-counted otherwise it seemed to be released automatically.

    AndroidManifest.xml:
    
    
    // Networking code:
    WifiManager wifi = getSystemService( Context.WIFI_SERVICE );
    MulticastLock lock = wifi.createMulticastLock("fliing_lock");
    lock.setReferenceCounted(true);
    lock.acquire();
    

    Just make sure to call lock.release() when you're done with it. This may only be necessary for Android 2.0+, The Droid is my only test device currently, so I can't say for sure.

提交回复
热议问题