Windows Phone 7 (WP7) development to obtain the network status

Source: Internet
Author: User

1. Determine whether a network data connection exists:

The most basic network status judgment, if there is no network connection, all operations will not continue.

 Microsoft.Phone.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()

 

Ii. Determine the network type (GSM/CDMA/WiFi/Ethernet ):

In general applications, three network statuses are required: No network, WiFi/Ethernet, and mobile phone network.

The difference is:

1. "No network": I don't explain it. Everyone knows it.

2. "WiFi/Ethernet": Generally, the speed is faster than that of the mobile phone network, regardless of traffic. It is more suitable for big data operations, such as downloading an offline map or something.

3. "mobile network": 2G and 3G networks are regarded as such. The advantage is convenience. As long as mobile phones and carriers support it and there is a signal, there is a network. The disadvantage is that the cost is high, and the speed is generally not as fast as the above.

We should provide appropriate services from the user's perspective based on the user's network environment. This requires you to determine the network status in the application and then take appropriate actions.

        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";
}
}

  

3. More detailed judgment on the network type (3g/2g/WiFi/Ethernet ):

In the 3G era, sometimes we need to know that the user's mobile phone network is 3G or 2G. (This method is displayed on the msdn Forum)

public static string NetName { get; set; }
public static void GetNetName()
{
DeviceNetworkInformation.ResolveHostNameAsync(
new DnsEndPoint("www.baidu.com", 80),
new NameResolutionCallback(handle =>
{
NetworkInterfaceInfo info = handle.NetworkInterface;
if (info != null)
{
switch (info.InterfaceType)
{
case NetworkInterfaceType.Ethernet:
NetName = "Ethernet";
break;
case NetworkInterfaceType.MobileBroadbandCdma:
case NetworkInterfaceType.MobileBroadbandGsm:
switch (info.InterfaceSubtype)
{
case NetworkInterfaceSubType.Cellular_3G:
case NetworkInterfaceSubType.Cellular_EVDO:
case NetworkInterfaceSubType.Cellular_EVDV:
case NetworkInterfaceSubType.Cellular_HSPA:
NetName = "3G";
break;
case NetworkInterfaceSubType.Cellular_GPRS:
case NetworkInterfaceSubType.Cellular_EDGE:
case NetworkInterfaceSubType.Cellular_1XRTT:
NetName = "2G";
break;
default:
NetName = "None";
break;
}
break;
case NetworkInterfaceType.Wireless80211:
NetName = "WiFi";
break;
default:
NetName = "None";
break;
}
}
else
NetName = "None";
}), null);
}

In my China Unicom WCDMA test, the network status is networkinterfacesubtype. cellular_3g. I guess that networkinterfacesubtype. cellular_hspa will appear in the GB WCDMA version.

As for TD-SCDMA, and CDMA 2000, unable to test because there is no device currently.

 

 

 

 

(

You are welcome to reprint it. Please indicate the source:

Jin yanycloud:

Http://www.cnblogs.com/vistach/archive/2012/02/09/Windows_Phone_WP7_Develop_NetworkInterface_3G_WCDMA_GSM_WiFi.html

)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.