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.

KaiserJohaan
  • 9,028
  • 20
  • 112
  • 199
  • 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. – Andy Oct 13 '11 at 12:19
  • I have tried this on HTC Desire and HTC EVO 3d. Both have this problem – KaiserJohaan Oct 13 '11 at 14:05
  • 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. – Reuben Scratton Oct 19 '11 at 08:50
  • There has to be a better way though, it feels too gimmicky – KaiserJohaan Oct 20 '11 at 07:17

2 Answers2

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

8bitwide
  • 2,071
  • 1
  • 17
  • 24
0

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

cistearns
  • 2,488
  • 21
  • 24