当前位置: 移动技术网 > IT编程>移动开发>Android > Android编程实现获取当前连接wifi名字的方法

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

2019年07月24日  | 移动技术网IT编程  | 我要评论

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网