wxr
2023-07-25 8309664bc53f72b0c808c339329cabcee87657c5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
 
namespace Shared.Net
{
    public  class WifiUtil
    {
        public  void ConnectToWifi(Action<bool> action, string wifiName, string wifiPwd = null)
        {
            var hotspotConfig = new NetworkExtension.NEHotspotConfiguration(wifiName, wifiPwd, false);
            NetworkExtension.NEHotspotConfigurationManager.SharedManager.ApplyConfiguration(hotspotConfig, (obj) =>
            {
                if (action != null)
                {
                    if (obj == null||obj.ToString().Contains("already associated"))
                    {
                        action(true);
                    }
                    else
                    {
                        action(false);
                    }
                }
            });
        }
 
        // 单例
        static WifiUtil ourInstance = new WifiUtil();
 
        public static WifiUtil Instance
        {
            get
            {
                return ourInstance;
            }
        }
 
 
        ///// <summary>
        ///// 获取WiFi列表
        ///// </summary>
        ///// <param name="mWifiManager"></param>
        ///// <returns></returns>
        //public List<string> GetWiFiList()
        //{
        //    if (!mWifiManager.IsWifiEnabled)
        //    {
        //        mWifiManager.SetWifiEnabled(true);
        //    }
        //    List<string> ssidList = new List<string>();
 
        //    IList<ScanResult> tempList = new List<ScanResult>();
        //    mWifiManager.StartScan();
        //    tempList = mWifiManager.ScanResults;
        //    foreach (var DD in tempList)
        //    {
        //        ssidList.Add(DD.Ssid);
        //    }
 
        //    return ssidList;
        //}
    }
}