首页 > 系统 > Android > 正文

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

2019-10-24 20:34:11
字体:
来源:转载
供稿:网友

这篇文章主要介绍了Android编程实现获取当前连接wifi名字的方法,涉及Android针对WiFi属性操作的相关技巧,需要的朋友可以参考下

本文实例讲述了Android编程实现获取当前连接wifi名字的方法。分享给大家供大家参考,具体如下:

 

  1. WifiManager wifiMgr = (WifiManager) mActivity.getSystemService(Context.WIFI_SERVICE); 
  2. int wifiState = wifiMgr.getWifiState(); 
  3. WifiInfo info = wifiMgr.getConnectionInfo(); 
  4. String wifiId = info != null ? info.getSSID() : null
  5. public static InetAddress getWifiIp() { 
  6. Context myContext = Globals.getContext(); 
  7. if (myContext == null) { 
  8. throw new NullPointerException("Global context is null"); 
  9. WifiManager wifiMgr = (WifiManager) myContext.getSystemService(Context.WIFI_SERVICE); 
  10. if (isWifiEnabled()) { 
  11. int ipAsInt = wifiMgr.getConnectionInfo().getIpAddress(); 
  12. if (ipAsInt == 0) { 
  13. return null
  14. else { 
  15. return Util.intToInet(ipAsInt); 
  16. else { 
  17. return null
  18. // 取得wifi的ip地址 
  19. InetAddress address = FTPServerService.getWifiIp(); 
  20. address.getHostAddress(); 
  21. public static boolean isWifiEnabled() { 
  22. Context myContext = Globals.getContext(); 
  23. if (myContext == null) { 
  24. throw new NullPointerException("Global context is null"); 
  25. WifiManager wifiMgr = (WifiManager) myContext.getSystemService(Context.WIFI_SERVICE); 
  26. if (wifiMgr.getWifiState() == WifiManager.WIFI_STATE_ENABLED) { 
  27. ConnectivityManager connManager = (ConnectivityManager) myContext 
  28. .getSystemService(Context.CONNECTIVITY_SERVICE); 
  29. NetworkInfo wifiInfo = connManager 
  30. .getNetworkInfo(ConnectivityManager.TYPE_WIFI); 
  31. return wifiInfo.isConnected(); 
  32. else { 
  33. return false
  34. // 打开wifi设置的页面 
  35. Intent intent = new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS); 
  36. startActivity(intent); 

希望本文所述对大家Android程序设计有所帮助。


注:相关教程知识阅读请移步到Android开发频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表