Windows Phone 8.1:检查 Internet 连接 [英] Windows Phone 8.1: Check Internet Connection

查看:38
本文介绍了Windows Phone 8.1:检查 Internet 连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何知道手机是否有互联网连接?(无论是 WiFi 还是数据)

How can I know if the phone has internet connection? (Whether WiFi or Data)

有时手机会在没有互联网连接的情况下连接到 WiFi,例如 HotSpots.所以我想要一个代码来知道手机是否连接到互联网.

Sometimes the phone is connecting to WiFi without internet connection like HotSpots. So I want a code to know if the phone is connecting to internet.

推荐答案

您可以简单地尝试:

 if (NetworkInformation.GetInternetConnectionProfile() == null)
        {
            //no connection
        }

正如您在此 msdn 文档中所见:NetworkInformation.GetInternetConnectionProfile

As you can see in this msdn documentation:NetworkInformation.GetInternetConnectionProfile

如果没有具有合适连接的连接配置文件",它将返回null

It will return null if there is "no connection profile with a suitable connection"

您还可以通过以下方式明确检查互联网访问"级别:NetworkInformation.GetInternetConnectionProfile().GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess

You can also check explicity the "Internet Access" level with this: NetworkInformation.GetInternetConnectionProfile().GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess

我认为这也适用于通用应用程序.

I Think this will work also in universal app.

这篇关于Windows Phone 8.1:检查 Internet 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆