开发者

How to prevent the phone from losing IP traffic?

I have a simple app that periodically sends HTTP_GET requests to a server. When sending requests over 3G, I noticed that the requests sometimes time out (and the server-side logging shows that it NEVER receives the request either).

After trying out different combinations I found one consistant pattern when this problem occures (it times out after every 5-15 successful requests).

- TelephonyRegistry: notifyDataConnection() state=2isDataConnectivityPossible()true, reason=null
 - TelephonyRegistry: broadcastDataConnectionStateChanged() state=开发者_JAVA百科CONNECTEDtypes=default supl, interfaceName=rmnet0
 - NetworkLocationProvider: onDataConnectionStateChanged 3

According to Google, NetworkLocationProvider is changed to 'DATA_SUSPENDED', which implies "connection is up, but IP traffic is temporarily unavailable". (see TelephonyManager). On the situations where HTTP_GET requests succeeds, the state is changed to '8'. My app doesn't use the location manage and I've shut down every other non-critical app from running!

I want to know:

  1. What is the cause of this issue? Why does the connection status go to DATA_SUSPENDED?
  2. Is it possible to avoid/overcome this problem?

Any help/insight into this is much appreciated! Thanks in advance!


I have the same problem with my app running on an Huawei IDEOS X3 with Android 2.3.5. The app sends data each minute to a server using HttpClient.

Using logcat I can see that the data connection is lost and then reestablished after a short while. Previously my app stopped working since it tried to send data without a connection causing an exception which was not properly handed.

I don't know the reason for the intermittently dropped data connection but I now handle the situation by checking if there is a data connection prior to sending the data. In my case it does not matter if some data is never sent. If it was important to avoid data loss, I could buffer the data and send it once the connection was back.

public Boolean isDataConnection() {
    TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    return tm.getDataState() == TelephonyManager.DATA_CONNECTED;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜