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;
|
//}
|
}
|
}
|