Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
421 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...