I'm working on a Android application that needs to receive UDP multicast packets from the local Wi-Fi network continously in the background. The reason for using multicast is the sender don't know the IP address of the device, so the sender can only send a multicast to discover the device(the packets contains a identifier and the device will check it and send a reply packet). But I have to use a MulticastLock to receive packets and when the screen goes off I can got nothing but actually I need to wake the device up by some packets. :(
I found some ways that forces the phone to keep the device awake by a WakeLock and uses a MulticastLock, or even roots the device and modify the WiFi driver. But I think it may noticeablely shorten the battery life so I wonder if there is a better solution to listen the UDP packets? I just want to wake up the device when a certain type of packet from a specified multicast group is received.
or is there any other way to establish communication with the phone when the IP address is unknown? The application have a pairing function so if any other identifiers needed to be exchanged can be exchanged here.