我使用下面的代码来检测互联网连接类型。
我尝试了以下条件:
问题: 在1和2条件下,代码仍然产生了一个结果: 接口类型6(“Internet连接(电缆))。这怎么可能?
我试过这个并得到同样的结果:
我想念什么?
private async void btnChkConnectionType_Click(object sender, RoutedEventArgs e) { var profile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile(); var interfaceType = profile.NetworkAdapter.IanaInterfaceType; // 71 is WiFi & 6 is Ethernet if (interfaceType == 71 ) { txtBlkConnectionStatus.Text = "WiFi connection"; } else if(interfaceType == 6) { txtBlkConnectionStatus.Text = "Internet connection (cable)"; } //3G/Mobile Detect else if (interfaceType == 243 || interfaceType == 244) { txtBlkConnectionStatus.Text = "Mobile Connection"; } else { txtBlkConnectionStatus.Text = "Not common connection type."; } }