I ran into the exact same problem! UDP packets would work on every phone except the Moto E. Then I found some very interesting information on the interwebz.
The problem was that the Moto E (and presumably the Moto G) requires the app to acquire WifiManager.MulticastLock
. From the android documentation -
Allows an application to receive Wifi Multicast packets. Normally the
Wifi stack filters out packets not explicitly addressed to this
device. Acquring a MulticastLock will cause the stack to receive
packets addressed to multicast addresses. Processing these extra
packets can cause a noticable battery drain and should be disabled
when not needed.
You need to add the following permission to your app -
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
And then in your code acquire a lock like so -
WifiManager wifi = (WifiManager)getSystemService( Context.WIFI_SERVICE );
if(wifi != null){
WifiManager.MulticastLock lock = wifi.createMulticastLock("Log_Tag");
lock.acquire();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…