I\'m trying to run an application using Android Native Service Discovery but sometimes when I run the application, it doesn\'t discover all services from my network. I\'m runnin
I was seeing the same issue with devices not being discovered and was able to fix it by acquiring the WifiManager Multicast lock prior to discovering services:
val multicastLock: WifiManager.MulticastLock = (mContext.getSystemService(Context.WIFI_SERVICE) as WifiManager).createMulticastLock(TAG)
multicastLock.setReferenceCounted(true)
multicastLock.acquire()
mNsdManager.discoverServices(SERVICE_TYPE, NsdManager.PROTOCOL_DNS_SD, mDiscoveryListener)
And later releasing the lock when done discovering services:
mNsdManager.stopServiceDiscovery(mDiscoveryListener)
multicastLock.release()