How can I determine whether I am connected to WiFi or a mobile network in Windows Phone 8.1 (Universal app)?

天涯浪子 提交于 2019-12-18 05:14:08

问题


I am working with a Windows Universal app (shared backend between Windows 8.1 and Windows Phone 8.1, not Silverlight). The app connects to Azure with Azure Mobile Services. In the settings for the app I would like to have an option for synchronisation to only occur over a WiFi network.

How can I determine if the phone is connected to WiFi or a mobile network? Although from my research I have found ways to do this with older versions of Windows Phone and with Silverlight, it seems I can only determine if the device is connected to the internet in a Windows Universal app.


回答1:


I believe you can determine this information from the ConnectionProfile using something akin to:

using Windows.Networking.Connectivity;

var connectionProfile = NetworkInformation.GetInternetConnectionProfile();
// connectionProfile can be null (e.g. airplane mode)
if (connectionProfile != null && connectionProfile.IsWlanConnectionProfile) {
    // do something over WiFi;
}

There is also the IsWwanConnectionProfile property, which is used to determine if the connection is via a 'mobile' connection (3g, etc).




回答2:


I think that this is the only way to check for internet availability :

bool IsConnected = NetworkInterface.GetIsNetworkAvailable();
        if (IsConnected)
        {
            // Do Something
        }
        else
        {
            // Do something different
        }

This Link is my reference.



来源:https://stackoverflow.com/questions/28852810/how-can-i-determine-whether-i-am-connected-to-wifi-or-a-mobile-network-in-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!