public static bool IsNetworkAvailable()
        {
            bool isAvailable = false;

            var profile = NetworkInformation.GetInternetConnectionProfile();

            if (profile == null) {
                return false;
            }

            var connections = profile.GetNetworkConnectivityLevel();

            switch (connections) {
                case NetworkConnectivityLevel.ConstrainedInternetAccess:
                case NetworkConnectivityLevel.InternetAccess:

                    isAvailable = true;

                    break;
                case NetworkConnectivityLevel.LocalAccess:
                case NetworkConnectivityLevel.None:

                    isAvailable = false;

                    break;

                default:
                    break;
            }

            return isAvailable;
        }

 

參考資料:

https://limzhenghong.wordpress.com/2013/10/26/checking-for-internet-connectivity-in-windows-8-cwinrt/

全站熱搜

小賢 發表在 痞客邦 留言(0) 人氣()