WindowsストアアプリでWiFiに接続されているかどうか調べます。
/// <summary> /// Property that returns the connection profile [ ie, availability of Internet ] /// Interface type can be [ 1,6,9,23,24,37,71,131,144 ] /// 1 -> Some other type of network interface. /// 6 -> An Ethernet network interface. /// 9 -> A token ring network interface. /// 23 > A PPP network interface. /// 24 > A software loopback network interface. /// 37 -> An ATM network interface. /// 71 -> An IEEE 802.11 wireless network interface. /// 131 -> A tunnel type encapsulation network interface. /// 144 -> An IEEE 1394 (Firewire) high performance serial bus network interface. /// </summary> public static bool IsConnectedToNetwork { get { var profile = NetworkInformation.GetInternetConnectionProfile(); if (profile != null) { var interfaceType = profile.NetworkAdapter.IanaInterfaceType; return interfaceType == 71 || interfaceType == 6; } return false; } }
関連記事
NetworkInformationクラスのGetInternetConnectionProfileメソッド
やNetworkAdapter.IanaInterfaceType
については、下記の記事で別途詳細を取り上げています。