I am making an applicati开发者_JAVA技巧on which makes use of the internet.
It works fine when the Wi-Fi is availble. But when the Wi-Fi is turned off, it gives me an error: "Address family not supported".
I am using the NetworkInfo
Class to know, if the network is available. Im using WifiManager to enable and manage Wi-fi connection if available.
I've been using the following code to check if a network is available:
ConnectivityManager mConnectivity = (ConnectivityManager) this
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = mConnectivity.getActiveNetworkInfo();
if (info == null) {
// No inet
}
精彩评论