Windows Phone Get network type (gsm/cdma/wifi/ethernet)

Source: Internet
Author: User

First, determine whether there is network data connection:

The most basic network state judgment, if there is no network connection, all operations will not go on.

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

Second, determine the network type (gsm/cdma/wifi/ethernet):

In the general application, need to know the network status is also three kinds: No network, wifi/ethernet, mobile network.

The difference between the three is:

1, "No network": Do not explain, we all understand.

2, "wifi/ethernet": generally faster than the mobile phone network, and does not count the traffic, more suitable for larger data operations, such as downloading an offline map or something.

3, "mobile network": 2G, 3G network is counted as such. The advantage is convenience, as long as the mobile phone and carrier support, as long as there is a signal, there is a network. The disadvantage is that the cost is higher, and the speed is generally not as fast as the above.

We do the application should consider from the user's perspective, according to the user's network environment, to provide the appropriate services. This requires determining the network state in the application and then taking the appropriate action.

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

Third, more detailed Judgment network type (3g/2g/wifi/ethernet):

In the 3G era today, sometimes we also need to know that the user's mobile network is 3G or 2G. (This method is seen 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);
}

My unicom WCDMA test, the network status of NETWORKINTERFACESUBTYPE.CELLULAR_3G, personal guess, WCDMA 3.5G version will appear networkinterfacesubtype.cellular_ HSPA.

As for TD-SCDMA, and CDMA2000, because there is no equipment, can not be tested.

Translated from: http://www.xnadevelop.com/post/2012/09/02/Windows-Phone-e88eb7e58f96e7bd91e7bb9ce78ab6e68081.aspx

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.