本文实例讲述了android编程实现获取当前连接wifi名字的方法。分享给大家供大家参考,具体如下:
wifimanager wifimgr = (wifimanager) mactivity.getsystemservice(context.wifi_service); int wifistate = wifimgr.getwifistate(); wifiinfo info = wifimgr.getconnectioninfo(); string wifiid = info != null ? info.getssid() : null; public static inetaddress getwifiip() { context mycontext = globals.getcontext(); if (mycontext == null) { throw new nullpointerexception("global context is null"); } wifimanager wifimgr = (wifimanager) mycontext.getsystemservice(context.wifi_service); if (iswifienabled()) { int ipasint = wifimgr.getconnectioninfo().getipaddress(); if (ipasint == 0) { return null; } else { return util.inttoinet(ipasint); } } else { return null; } } // 取得wifi的ip地址 inetaddress address = ftpserverservice.getwifiip(); address.gethostaddress(); public static boolean iswifienabled() { context mycontext = globals.getcontext(); if (mycontext == null) { throw new nullpointerexception("global context is null"); } wifimanager wifimgr = (wifimanager) mycontext.getsystemservice(context.wifi_service); if (wifimgr.getwifistate() == wifimanager.wifi_state_enabled) { connectivitymanager connmanager = (connectivitymanager) mycontext .getsystemservice(context.connectivity_service); networkinfo wifiinfo = connmanager .getnetworkinfo(connectivitymanager.type_wifi); return wifiinfo.isconnected(); } else { return false; } } // 打开wifi设置的页面 intent intent = new intent(android.provider.settings.action_wifi_settings); startactivity(intent);
希望本文所述对大家android程序设计有所帮助。
如对本文有疑问, 点击进行留言回复!!
Android studio开发小型对话机器人app(实例代码)
Android通过Java sdk的方式接入OpenCv的方法
Android 通过cmake的方式接入opencv的方法步骤
Android Studio finish()方法的使用与解决app点击“返回”(直接退出)
Android 进度条 ProgressBar的实现代码(隐藏、出现、加载进度)
网友评论