欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android编程实现获取当前连接wifi名字的方法

程序员文章站 2023-12-09 13:53:03
本文实例讲述了android编程实现获取当前连接wifi名字的方法。分享给大家供大家参考,具体如下: wifimanager wifimgr = (wifiman...

本文实例讲述了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程序设计有所帮助。