UDP broadcast packets not received in sleep mode

和自甴很熟 提交于 2019-11-29 08:48:31

This Google Groups thread deals with the problem:

https://groups.google.com/forum/?fromgroups=#!topic/android-platform/OpbSdp9FTmA

It has to do with certain chipsets and deep sleep. Basically, drivers detect when the device goes into a deep sleep and shut down UDP Broadcast Reception. In my experience, UDP send still works and a UDP send/listen on the device will also hear packets, but it's a ghost, the device is actually deaf.

The following recommendation is what I use:

  1. Acquire a PARTIAL_WAKE_LOCK, and trap when the screen goes off. Then disable and reenable the wifi. This works because the filter only turns on when the screen goes off, so starting wifi with the screen off will keep it working until the screen goes off again. This is what we did before we figured out solution (1).
bragasil

I use this:

WifiManager wifi;
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
MulticastLock wifilock = wifi.createMulticastLock("just some tag text");
wifilock.acquire();

manifest:

permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!