using System;
|
using Android.Net.Wifi;
|
|
namespace Shared
|
{
|
public static class WiimuUPnP
|
{
|
/// <summary>
|
/// 获取当前WIFI的名称
|
/// </summary>
|
/// <value>The ssid.</value>
|
public static string SSID
|
{
|
get
|
{
|
WifiManager wifiManager = (WifiManager)Application.Activity.GetSystemService(Android.Content.Context.WifiService);
|
WifiInfo wifiInfo = wifiManager.ConnectionInfo;
|
if (wifiInfo != null)
|
{
|
if (wifiInfo.SSID != null)
|
{
|
return wifiInfo.SSID.Trim('"');
|
}
|
return null;
|
}
|
else
|
{
|
return null;
|
}
|
}
|
}
|
|
static Action<string> currentAction;
|
/// <summary>
|
/// 启动配置无线上网
|
/// </summary>
|
/// <returns>The start.</returns>
|
/// <param name="password">密码</param>
|
/// <param name="a">配置完成后反馈的结果</param>
|
public static void Start(string password,Action<string> action)
|
{
|
if (SSID == null)
|
{
|
return;
|
}
|
|
Stop();
|
dateTime = DateTime.Now;
|
currentAction = action;
|
action ("TimeOut");
|
}
|
|
static WiimuUPnP()
|
{
|
//定时检查
|
System.Threading.Tasks.Task.Run(() =>
|
{
|
while (true)
|
{
|
System.Threading.Thread.Sleep(1000);
|
if (20 <= (System.DateTime.Now - dateTime).TotalSeconds)
|
{
|
Stop();
|
if (currentAction != null)
|
{
|
currentAction("TimeOut");
|
}
|
}
|
}
|
});
|
}
|
|
/// <summary>
|
/// 记录开始时间
|
/// </summary>
|
static DateTime dateTime = DateTime.MaxValue;
|
|
/// <summary>
|
/// 停止配置无线上网
|
/// </summary>
|
public static void Stop()
|
{
|
dateTime = DateTime.MaxValue;
|
|
}
|
|
}
|
|
}
|