我正在尝试使用以下代码段在Windows Phone 8.0设备上获得活动网络连接。当我禁用Wifi和移动设备时,我希望找不到连接的接口,但有趣的是一个名称为" Ethernet"似乎有联系。什么是移动设备上的以太网适配器?
foreach (NetworkInterfaceInfo networkInterfaceInfo in networkInterfaceList)
{
if (networkInterfaceInfo.InterfaceState == ConnectState.Connected)
{
isConnected = true;
if (networkInterfaceInfo.InterfaceType == NetworkInterfaceType.MobileBroadbandGsm
|| networkInterfaceInfo.InterfaceType == NetworkInterfaceType.MobileBroadbandCdma)
isMobileConnected = true;
else if (networkInterfaceInfo.InterfaceType == NetworkInterfaceType.Wireless80211)
isWifiConnected = true;
}
}
还有一种方法可以获得一个活跃的网络"信息?例如,如果移动和wifi都启用并连接,我怎么知道实际使用哪一个?
由于
答案 0 :(得分:2)
您可以找到NetworkAdapter
类的网络类型。它有财产IanaInterfaceType
要检查所有IANA界面,请转到here
var profile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
var interfaceType = profile.NetworkAdapter.IanaInterfaceType;
// 71 is WiFi & 6 is Ethernet(LAN)
if (interfaceType == 71 || interfaceType == 6)
{
//TODO:
}
// 243 & 244 is 3G/Mobile
else if (interfaceType == 243 || interfaceType == 244)
{
//TODO:
}
希望它有所帮助:)
答案 1 :(得分:-1)
试试这个:
private void UpdateNetworkStatus()
{
tbIsCellularDataEnabled.Text = (DeviceNetworkInformation.IsCellularDataEnabled) ? "Yes" : "No";
tbIsNetworkAvailable.Text = (DeviceNetworkInformation.IsNetworkAvailable) ? "Yes" : "No";
tbIsWiFiEnabled.Text = (DeviceNetworkInformation.IsWiFiEnabled) ? "Yes" : "No";
}