如何确定我是否在Windows Phone 8.1(通用应用程序)中连接到WiFi或移动网络?
我正在使用Windows Universal应用程序(Windows 8.1和Windows Phone 8.1之间的共享后端,而不是Silverlight)。 该应用程序通过Azure移动服务连接到Azure。 在应用程序的设置中,我希望只有通过WiFi网络才能进行同步选项。
如何确定手机是连接到WiFi还是移动网络? 虽然从我的研究中我已经找到了使用旧版Windows Phone和Silverlight的方法,但似乎我只能确定该设备是否在Windows Universal应用程序中连接到互联网。
我相信你可以使用类似于以下内容的东西从ConnectionProfile
确定这些信息:
using Windows.Networking.Connectivity; var connectionProfile = NetworkInformation.GetInternetConnectionProfile(); // connectionProfile can be null (eg airplane mode) if (connectionProfile != null && connectionProfile.IsWlanConnectionProfile) { // do something over WiFi; }
还有IsWwanConnectionProfile
属性,用于确定连接是否通过“移动”连接(3g等)。
我认为这是检查互联网可用性的唯一方法:
bool IsConnected = NetworkInterface.GetIsNetworkAvailable(); if (IsConnected) { // Do Something } else { // Do something different }
这个链接是我的参考。