Android - native sockets not removing 3G-sleep-mode on first attempt
Asked Answered
G

2

7

I have a really annoying problem. What happens is I have an application which is using native sockets to send data over TCP. When I first launch my application and send data over the sockets, nothing gets through. However if I then quit the process and restart it and then send again, it works. Same thing if I open the browser or something before starting my app for the first time after sleep mode.

How do I 'force' 3G to go out of sleep mode before I make the call to the native code?

EDIT: I have already tried with PowerManager.

Glucoside answered 13/10, 2011 at 11:51 Comment(4)
Have you tried this on some other device? I have some related problems with native UDP socket on my HTC Desire, but no problems on several Samsung Galaxys, Huawei's or Sony Ericsson phones.Magallanes
I have tried this on HTC Desire and HTC EVO 3d. Both have this problemGlucoside
Maybe just expect the first try to fail, and then retry a second or two later? Or, issue a dummy HttpGetRequest to www.example.com, say, to wake up the networking layers before trying your real network code.Emissivity
There has to be a better way though, it feels too gimmickyGlucoside
F
0

Try calling startUsingNetworkFeature (int networkType, String feature) On a ConnectivityManager and wait for it to be available before you bind your sockets ect......

Android Documentation

Fabrin answered 21/10, 2011 at 0:31 Comment(0)
P
0

I'd give the ConnectivityManager API requestRouteToHost(int networkType, int hostAddress) a try.

Primary answered 21/10, 2011 at 1:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.