判断有网没网
/**
* Check whether the device is connected, and if so, whether the connection
* is wifi or mobile (it could be something else).
*/
private void checkNetworkConnection() {
// BEGIN_INCLUDE(connect)
ConnectivityManager connMgr =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeInfo = connMgr.getActiveNetworkInfo();
if (activeInfo != null && activeInfo.isConnected()) {
wifiConnected = activeInfo.getType() == ConnectivityManager.TYPE_WIFI;
mobileConnected = activeInfo.getType() == ConnectivityManager.TYPE_MOBILE;
if(wifiConnected) {
Log.i(TAG, getString(R.string.wifi_connection));
} else if (mobileConnected){
Log.i(TAG, getString(R.string.mobile_connection));
}
} else {
Log.i(TAG, getString(R.string.no_wifi_or_mobile));
}
// END_INCLUDE(connect)
}
继续阅读与本文标签相同的文章
上一篇 :
Keras 构建CNN
下一篇 :
焕新升级 一网通办 四川政务服务网改版上线
-
你还在用360吗?曾必不可少到现在被人“嫌弃”,只因这1点原因
2026-05-18栏目: 教程
-
Java 12 新特性概述
2026-05-18栏目: 教程
-
Wifi上线!威海市图书馆无线网免费开放
2026-05-18栏目: 教程
-
企业如何选择网络安全防护公司?
2026-05-18栏目: 教程
-
调查显示:中国88%员工信任机器人超过经理
2026-05-18栏目: 教程
