Keerthi Jayarajan
Keerthi Jayarajan

Reputation: 477

In Android, UDP packets not received in sleep mode

I have implemented a udp packets recevier thread which listens for the reception of UDP packtes. It works fine when the screen is ON. When the power button is pressed, device goes into sleep mode. After that It is not receving any UDP packets. And It receives packet only when screen comes to ON state. This is not the case in Sony Xperia Z tablet. It receives UDP packets all the time regardless of screen ON or OFF state.

I have used PowerManager.PARTIAL_WAKE_LOCK to ensure that CPU is running in sleep mode. But there is no difference with that. I am wondering what causes the UDP packets blocked in sleep mode. Please help me to understand why UDP packets are blocked in receving and who blocks it? And also I am looking for a solution for this.

Upvotes: 0

Views: 770

Answers (2)

caspii
caspii

Reputation: 869

This thread deals with the problem: https://groups.google.com/forum/?fromgroups=#!topic/android-platform/OpbSdp9FTmA

Bascially, the solution is

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.

Upvotes: 1

sasebt
sasebt

Reputation: 1

try using WiFi Lock:

WifiLock wl = ((WifiManager) getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL, "wifi_lock"); wl.acquire();

... do your stuff here, and when done:

wl.release ();

Upvotes: 0

Related Questions