UDP broadcast packets being blocked

Apparently UDP packets sent with a broadcast address such as will be blocked by some versions of Android (which is the case with my Motorola MotoG phone). To get around this, some people recommended using WifiManager.MulticastLock when creating the listening socket. This works, but only temporarily. I am finding that only a handful of these broadcast packets get through before Android blocks them again. Does anyone have a suggestion? Below is the code snippet.

val wifiManager: WifiManager = getApplicationContext().getSystemService(WIFI_SERVICE) as WifiManager
val lock: MulticastLock = wifiManager.createMulticastLock(“Log_Tag”)
val socketIn = MulticastSocket(4000)
val packetIn = DatagramPacket(buffer, buffer.size)

You probably want to try stack overflow. This isn’t really a Kotlin question. I would suspect that you will need to read the documentation. Android has various policies trying to avoid app abuse.