开发者

Android Wi-Fi: 'Address family not supported'

开发者 https://www.devze.com 2023-01-14 22:26 出处:网络
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 suppo

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
}
0

精彩评论

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