android的组播真是够麻烦的
1. 打开权限
2. 打开组播锁,默认时,移动设备为了省电是关闭的
WifiManagerwifi=(WifiManager)getSystemService(Context.WIFI_SERVICE);if(wifi!=null){MulticastLockmcLock=wifi.createMulticastLock("mylock");mcLock.acquire();...
3. 模拟器玩wifi还是很痛苦的,莫名其妙的错误和失败
4. 真机玩wifi组播也很要命,根据stackoverflow,android2.3.7以下的系统只能接收自己发送的组播消息,无法接收其他设备,包括移动设备,PC等发送的组播消息
I've been doing a bit of research into this, and I believe it is a problem with Android in general, and fixed in or around Android 2.3.7.
It's a bit too anecdotal, but here's what I tested:
HTC Desire, 2.2, stock: fail
HTC Desire, 2.3.7, CyanogenMod: success
Motorola Milestone, 2.1-update1: fail
HTC Desire S, 2.3.3: fail
Acer Iconia A501, 3.2.1: success
Samsung something, 2.3.3: fail
HTC Legend, 2.2 I think: fail
When I say 'fail', in fact they were all able to send multicast messages to the 'success' devices, but never receive anything back except their own messages - as jldupont describes.
手头只有一台老旧的索爱X8,android2.1, 接收组播异常
一台小米1s,android4.0,可以正常接收PC的组播