Android编程实现获取当前连接wifi名字的方法
本文实例讲述了Android编程实现获取当前连接wifi名字的方法。分享给大家供大家参考,具体如下:
WifiManagerwifiMgr=(WifiManager)mActivity.getSystemService(Context.WIFI_SERVICE); intwifiState=wifiMgr.getWifiState(); WifiInfoinfo=wifiMgr.getConnectionInfo(); StringwifiId=info!=null?info.getSSID():null; publicstaticInetAddressgetWifiIp(){ ContextmyContext=Globals.getContext(); if(myContext==null){ thrownewNullPointerException("Globalcontextisnull"); } WifiManagerwifiMgr=(WifiManager)myContext.getSystemService(Context.WIFI_SERVICE); if(isWifiEnabled()){ intipAsInt=wifiMgr.getConnectionInfo().getIpAddress(); if(ipAsInt==0){ returnnull; }else{ returnUtil.intToInet(ipAsInt); } }else{ returnnull; } } //取得wifi的ip地址 InetAddressaddress=FTPServerService.getWifiIp(); address.getHostAddress(); publicstaticbooleanisWifiEnabled(){ ContextmyContext=Globals.getContext(); if(myContext==null){ thrownewNullPointerException("Globalcontextisnull"); } WifiManagerwifiMgr=(WifiManager)myContext.getSystemService(Context.WIFI_SERVICE); if(wifiMgr.getWifiState()==WifiManager.WIFI_STATE_ENABLED){ ConnectivityManagerconnManager=(ConnectivityManager)myContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfowifiInfo=connManager .getNetworkInfo(ConnectivityManager.TYPE_WIFI); returnwifiInfo.isConnected(); }else{ returnfalse; } } //打开wifi设置的页面 Intentintent=newIntent(android.provider.Settings.ACTION_WIFI_SETTINGS); startActivity(intent);
希望本文所述对大家Android程序设计有所帮助。