如何workerman用的是text协议,ios和android怎么连接上
发布网友
发布时间:2022-04-07 08:23
我来回答
共2个回答
热心网友
时间:2022-04-07 09:52
通过设备开通WiFi连接获取Mac地址是最可取的,代码如下:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* 设备开通WiFi连接,通过wifiManager获取Mac地址
*
* @author 高焕杰
*/
public static String getMacFromWifi(Context context){
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
State wifiState = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
if(wifiState == NetworkInfo.State.CONNECTED){//判断当前是否使用wifi连接
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
if (!wifiManager.isWifiEnabled()) { //如果当前wifi不可用
wifiManager.setWifiEnabled(true);
}
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
return wifiInfo.getMacAddress();
}
return null;
}
热心网友
时间:2022-04-07 11:10
public static String getMacFromWifi(Context context){
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
State wifiState = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
if(wifiState == NetworkInfo.State.CONNECTED){//判断当前是否使用wifi连接
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
if (!wifiManager.isWifiEnabled()) { //如果当前wifi不可用
wifiManager.setWifiEnabled(true);
}
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
return wifiInfo.getMacAddress();
}
return null;
}