Check connection using ConnectivityManager
suggest changeDeclare ACCESS_NETWORK_STATE. This reports whether a network is connected or connecting. It does not prove that a remote host answered.
public static boolean isConnectedNetwork(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm == null) {
return false;
}
NetworkInfo info = cm.getActiveNetworkInfo();
return info != null && info.isConnectedOrConnecting();
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents