user533844
user533844

Reputation: 2063

Android cell phone - how to handle intermittent connectivity

I am not sure this problem belongs here.... but still ....

My application exchange's data with server every 3 minutes. I am using honeycomb tablet on cell phone coverage(not Wi-Fi). If a person is using it where there is no cell phone covearge he is not going to get new data. How do I deal with this situation? What do I do in the application?

Upvotes: 2

Views: 441

Answers (1)

coder_For_Life22
coder_For_Life22

Reputation: 26981

Here this will allow you to test for WIFI and 3g/4g coverage:

private boolean hasNetworkConnection() {

  boolean haveConnectedWifi = false;
  boolean haveConnectedMobile = false;

  ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo[] netInfo = cm.getAllNetworkInfo();

  for (NetworkInfo ni : netInfo) {
    if (ni.getTypeName().equalsIgnoreCase("WIFI"))
      if (ni.isConnected())
        haveConnectedWifi = true;
    if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
      if (ni.isConnected())
        haveConnectedMobile = true;
  }

  return haveConnectedWifi || haveConnectedMobile;
}

Upvotes: 1

Related Questions