string status="";
if (DeviceNetworkInformation.IsWiFiEnabled)
{
if (DeviceNetworkInformation.IsCellularDataEnabled == false && DeviceNetworkInformation.IsNetworkAvailable == true)
{
status= "WiFi Status: On and Connected!";
}
else
{
status = "WiFi Status: On but not connected!";
}
}
else
{
status = "Wifi is Off";
}
提前致谢:) 我想在wp8.1中实现相同的功能,但在WP8.1中没有预设Microsoft.Phone API。
答案 0 :(得分:0)
对于Windows(电话)8.1,网络信息是ConnectionProfile
命名空间中Windows.Networking.Connectivity
的一部分。
IsWlanConnectionProfile
表示连接配置文件是否代表WLAN(WiFi)连接。
NetworkConnectivityLevel
表示当前有哪些网络资源可用。
ConnectionProfile internetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
if (internetConnectionProfile.IsWlanConnectionProfile )
{
if ( internetConnectionProfile.GetNetworkConnectivityLevel() ==
NetworkConnectivityLevel.InternetAccess)
{
status= "WiFi Status: On and Connected!";
}
else
{
status = "WiFi Status: On but not connected!";
}
}
else
{
status = "Wifi is Off";
}
你可以走这条路,但不建议这样做。
来自MSDN:
在某些情况下,GetNetworkConnectivityLevel方法可能需要一些时间来确定网络连接级别的当前值。确定网络连接级别的建议过程是在NetworkInformation类上注册
NetworkStatusChanged
事件的处理程序。收到有关网络状态更改的通知时,通过调用GetInternetConnectionProfile方法返回的配置文件上的GetNetworkConnectivityLevel方法获取新的连接级别。然后可以存储返回的网络连接级别以供以后在需要时使用。这也确保检查正确的ConnectionProfile。
希望这有帮助!