2013-12-11 31 views
1

我使用下面的代码来检测Internet连接类型。如何检测WinRT应用程序的Internet连接类型

我尝试以下条件:

  1. 断开无线上网为笔记本
  2. 用于笔记本

问题断开有线互联网连接: 与上述图1和2的条件,将码仍然产生了一个结果: 接口类型6(“Internet连接(电缆))。这怎么可能?

我尝试这样做,结果是一样的:

  1. 连接到WiFi网络
  2. 断开电缆连接互联网

我怎么错过?

 

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

      } 


     } 

回答

-1

尝试在物理设备上你的代码。仿真器不知道主机的连接类型,因此它将所有连接视为单个连接,即电缆连接。

在模拟器上,检查wifi状态(在设置页面上)。默认状态是“关闭”。

+1

JS,请不要让答案看起来像问题。我编辑它相应,因为它看起来像一个答案(不是评论)。谢谢。 – Drew

相关问题