[英]How can I tell if a phone is connected by wifi or has access to mobile internet via C#?
When the phone is in the local network it has ip 192.168.0.x
when it is outside wifi access it uses internet connection provided by mobile network(the internet accessed when you have sim inside the phone). 当手机在本地网络中时,当它在wifi外时它的IP为192.168.0.x
,它使用移动网络提供的互联网连接(当您在手机中装有sim卡时可以访问互联网)。
How to determine by C# which kind of connection is used at the time? 如何通过C#确定当时使用哪种连接?
EDIT: 编辑:
NetworkInterfaceInfo netInterfaceInfo = socket.GetCurrentNetworkInterface();
var type = netInterfaceInfo.InterfaceType;
var subType = netInterfaceInfo.InterfaceSubtype;
You can try this method to check network states: 您可以尝试使用此方法检查网络状态:
public static string GetNetStates()
{
var info = Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType;
switch (info)
{
case NetworkInterfaceType.MobileBroadbandCdma:
return "CDMA";
case NetworkInterfaceType.MobileBroadbandGsm:
return "CSM";
case NetworkInterfaceType.Wireless80211:
return "WiFi";
case NetworkInterfaceType.Ethernet:
return "Ethernet";
case NetworkInterfaceType.None:
return "None";
default:
return "Other";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.