Android编程实现获取当前连接wifi名字的方法
作者:lee0oo0 时间:2023-11-24 15:41:50
本文实例讲述了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,wifi
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Spring MVC 基于URL的映射规则(注解版)
2021-05-23 15:05:09
C语言实现顺序表的顺序查找和折半查找
2021-10-24 13:17:19
java多线程之CyclicBarrier的使用方法
2023-11-04 21:52:54
一个简单的Python名片管理系统
2022-09-20 09:26:15
Android Intent传递大量数据出现问题解决
2021-11-07 10:16:13
c# 服务器上传木马监控代码(包含可疑文件)
2022-07-08 10:02:45
SpringBoot2.0 ZipKin示例代码
2022-11-25 00:24:40
![](https://img.aspxhome.com/file/2023/9/70989_0s.png)
SpringBoot学习篇之@Valid与@Validated的区别
2021-08-07 21:38:41
![](https://img.aspxhome.com/file/2023/0/118830_0s.png)
异常try catch的常见四类方式(案例代码)
2023-11-10 23:18:00
IntelliJ IDEA 2017 汉化包及图文教程
2023-11-25 12:17:58
![](https://img.aspxhome.com/file/2023/0/59570_0s.jpg)
Java NIO实现多人聊天室
2022-04-05 09:03:17
![](https://img.aspxhome.com/file/2023/4/62964_0s.jpg)
浅析C#中文件路径的操作
2023-11-09 16:24:30
MyBatis的逆向工程详解
2022-12-03 11:06:10
Spring Boot + Vue 前后端分离开发之前端网络请求封装与配置
2021-05-28 02:48:41
![](https://img.aspxhome.com/file/2023/5/79185_0s.png)
Android实现分享长图并且添加全图水印
2021-08-04 19:30:57
C#和vb.net实现PDF 添加可视化和不可见数字签名
2022-08-01 12:49:02
![](https://img.aspxhome.com/file/2023/2/87042_0s.png)
详解如何将Spring Boot应用跑在Docker容器中
2023-04-25 08:08:58
![](https://img.aspxhome.com/file/2023/8/77158_0s.jpg)
android studio生成aar包并在其他工程引用aar包的方法
2021-07-23 21:28:30
![](https://img.aspxhome.com/file/2023/2/130302_0s.jpg)
Android开发之SD卡文件操作分析
2022-01-09 04:55:16
C#使用GDI+创建缩略图实例
2023-02-21 01:57:16