当wifi连接到无线调制解调器互联网覆盖是否存在它总是说是你连接它只检查wifi连接而不是互联网连接所以如何处理这种情况?
1.)你可以检查它
URL url = new URL("YOUR urlString");
HttpURLConnection conn= (HttpURLConnection) url.openConnection();
.
.
int responseCode = conn.getResponseCode();
//if responseCode = 200 - THEn CONN is connected
Run Code Online (Sandbox Code Playgroud)
或者
2.)你可以做一些像dis这样的事情
public static boolean isNetworkAvailable(Activity activity) {
ConnectivityManager connectivity = (ConnectivityManager) activity
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
return false;
} else {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true; //<-- -- -- Connected
}
}
}
}
return false; //<-- -- -- NOT Connected
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5297 次 |
| 最近记录: |