如何检测WinRT App的Internet连接类型

时间:2013-12-11 14:29:36

标签: windows-phone-8 windows-runtime

我使用下面的代码来检测互联网连接类型。

我尝试了以下条件:

  1. 断开笔记本电脑的Wifi
  2. 断开笔记本电脑的有线互联网连接
  3. 问题: 在1和2条件下,代码仍然产生了一个结果: 接口类型6(“Internet连接(电缆))。这怎么可能?

    我试过这个并得到同样的结果:

    1. 连接到Wifi
    2. 断开有线互联网连接
    3. 我想念什么?

      
        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.";
      
                  } 
      
      
              }