如何查找用户是否使用有线连接到互联网?
以下是我目前的进展
var internetConnectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
if (internetConnectionProfile.GetNetworkConnectivityLevel() == Windows.Networking.Connectivity.NetworkConnectivityLevel.InternetAccess)
{
// has internet connection
}
if (internetConnectionProfile.IsWwanConnectionProfile)
{
// its mobile
}
if (internetConnectionProfile.IsWlanConnectionProfile)
{
// its wireless
}
答案 0 :(得分:2)
试试这个
bool IsWiredInternetAccess()
{
IReadOnlyList<ConnectionProfile> connections = NetworkInformation.GetConnectionProfiles();
foreach (var connection in connections)
{
if (connection == null) continue;
if (connection.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess)
{
// check is connection wired
if ((connection.ConnectionProfile.IsWlanConnectionProfile)||(connection.IsWwanConnectionProfile))
{
// connection is Wlan or Wwan
return false;
}
else
{
return true;
}
}
}
}
答案 1 :(得分:0)
这是一个简单且更新的答案
更新的ConnectionProfile类有助于识别网络连接的类型。
ConnectionProfile connectionProfile = NetworkInformation.GetInternetConnectionProfile();
bool isWifi = connectionProfile.IsWlanConnectionProfile;