WEB开发网
开发学院手机开发Android 开发 android平台判断Wifi连接 阅读

android平台判断Wifi连接

 2012-09-17 20:40:53 来源:WEB开发网   
核心提示: private boolean checkConnection(){ boolean connected = false; ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); if

 private boolean checkConnection(){


boolean connected = false;
ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);

if (cm != null) {
NetworkInfo[] netInfo = cm.getAllNetworkInfo();

for (NetworkInfo ni : netInfo) {
if ((ni.getTypeName().equalsIgnoreCase("WIFI")
|| ni.getTypeName().equalsIgnoreCase("MOBILE"))
& ni.isConnected() & ni.isAvailable()) {
connected = true;
}

}
}


return connected;

Tags:android 平台 判断

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接