2015-09-29 5 views

答えて

21

UWPでは、IsWlanConnectionProfileプロパティまたはIsWwanConnectionProfileプロパティを使用してネットワーク接続を確認できます。

例は次のようになります。

var temp = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile(); 

if (temp.IsWlanConnectionProfile) 
{ 
    // its wireless 
}else if (temp.IsWwanConnectionProfile) 
{ 
    // its mobile 
} 

私はこのことができます願っています。

+2

「temp」が「null」の場合もチェックする必要があります。 – Nick

9

接続性を得るだけでなく(他の人も触れた)、計測された接続をより適切に処理することができます。

How to manage metered network cost constraints

switch (connectionCost.NetworkCostType) 
{ 
    case NetworkCostType.Unrestricted: 
     // 
     break; 
    case NetworkCostType.Fixed: 
     // 
     break; 
    case NetworkCostType.Variable: 
     // 
     break; 
    case NetworkCostType.Unknown: 
     // 
     break; 
    default: 
     // 
     break; 
} 

networking demo at GitHubを参照してください。

if (connectionCost.Roaming || connectionCost.OverDataLimit) 
{ 
    Cost = NetworkCost.OptIn; 
    Reason = connectionCost.Roaming 
     ? "Connection is roaming; using the connection may result in additional charge." 
     : "Connection has exceeded the usage cap limit."; 
} 
else if (connectionCost.NetworkCostType == NetworkCostType.Fixed 
    || connectionCost.NetworkCostType == NetworkCostType.Variable) 
{ 
    Cost = NetworkCost.Conservative; 
    Reason = connectionCost.NetworkCostType == NetworkCostType.Fixed 
     ? "Connection has limited allowed usage." 
     : "Connection is charged based on usage. "; 
} 
else 
{ 
    Cost = NetworkCost.Normal; 
    Reason = connectionCost.NetworkCostType == NetworkCostType.Unknown 
     ? "Connection is unknown" 
     : "Connection cost is unrestricted"; 
} 
関連する問題