There are a number of questions regarding how to detect network connectivity in Android. https://stackoverflow.com/a/4239019/90236 provides a very detailed answer and https://stackoverflow.com/a/8548926/90236 shows methods to identify the type of network to which one is connected.
We detect network connectivity using code similar to those answers like:
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
This lets us warn a user if they are offline. However, it doesn't help us identify if a user has limited connectivity. There are conditions of limited connectivity that have caused users to complain. These include:
Users are connected to a home wifi network but the cable modem or Internet service is unavailable.
Users are in a hotel or coffee shop and successfully connect to a wifi network, but the network requires that they login or agree to terms of service before they are given full network access.
In both of these situations our isNetworkAvailable() test returns true. The OS tells us we are connected to a network. However, the user does not have usable Internet connectivity.
Is there a good way to determine that the user has a fully functioning network connection?
I'm considering calling a lightweight web service to verify their connectivity and warn the user if the app doesn't get a valid return from the service. Is this overkill? or have others had to resort to similar techniques?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…