Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
791 views
in Technique[技术] by (71.8m points)

android - UDP broadcast packets not received in sleep mode

My Android application periodically sends and receives UDP broadcast messages on the WiFi LAN. When the display is on, everything works fine and all messages are sent and received correctly. When the display goes to sleep the application however stops receiving UDP broadcast messages (but still sends them).

Acquiring the WiFiLock (as well as a Multicast Lock) does not seem to make any difference and my wifi sleep policy is set to WIFI_SLEEP_POLICY_NEVER.

This is an issue on Android 2.3.3 and 2.3.5 (Samsung galaxy SII phones) but not an issue on an old HTC Hero running cyanogen mod with android 2.3.7.

Has anyone else had this problem and found a solution?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...