Windows Phone 7

Source: Internet
Author: User

The networkinterface class and networkinterfacetype class under Microsoft. Phone. net. networkinformation are related to the network information of Windows Phone 7. Networkinterface provides some information about the current mobile phone network. networkinterfacetype is an enumeration of the type of mobile phone network.
The following example uses networkinterface and networkinterfacetype to check the network status of the mobile phone.

<Grid X: Name = "layoutroot" background = "Transparent"> <grid. rowdefinitions> <rowdefinition Height = "Auto"/> <rowdefinition Height = "*"/> </grid. rowdefinitions> <stackpanel X: Name = "titlepanel" grid. row = "0" margin = ","> <textblock X: Name = "pagetitle" text = "Check mobile network" margin = "9, 0 "style =" {staticresource phonetexttitle1style} "/> </stackpanel> <grid X: Name =" contentpanel "grid. row = "1" margin = "12, 0, 131,184 "> <textbox name =" message "background =" yellow "text =" unknown "verticalignment =" center "horizontalalignment =" center "margin =, 94,378 "width =" 231 "/> <button content =" view Network Information "Height =" 72 "horizontalalignment =" Left "margin =, 244 "name =" button1 "verticalignment =" TOP "width =" 131,271 "Click =" button#click "/> <textbox Height =" 72 "horizontalalignment =" Left "margin = ", 244 "name =" netname "text =" textbox "verticalalignment =" TOP "width =" 9,198 "/> <textblock Height =" 49 "horizontalalignment =" Left "margin =", 121 "name =" textblock1 "text =" network status: "verticalalignment =" TOP "width =" 9,287 "/> <textblock horizontalalignment =" Left "margin =, 0,310 "name =" textblock2 "text =" network type: "/> </GRID>
Using system; using system. collections. generic; using system. LINQ; using system. net; using system. windows; using system. windows. controls; using system. windows. documents; using system. windows. input; using system. windows. media; using system. windows. media. animation; using system. windows. shapes; using Microsoft. phone. controls; using system. net. networkinformation; using Microsoft. phone. net. networkinformation; namespace checknet {public partial class mainpage: phoneapplicationpage {private bool networkisavailable; private networkinterfacetype _ currentnetworktype; // public mainpage () {initializecomponent ();} private void button#click (Object sender, routedeventargs e) {networkisavailable = Microsoft. phone. net. networkinformation. networkinterface. getisnetworkavailable (); // whether the current network is available _ currentnetworktype = Microsoft. phone. net. networkinformation. networkinterface. networkinterfacetype; // obtain the current network type if (networkisavailable) {message. TEXT = "Networking status"; message. background = new solidcolorbrush (colors. green);} else {message. TEXT = "disconnected"; message. background = new solidcolorbrush (colors. red);} switch (_ currentnetworktype) {Case networkinterfacetype. mobilebroadbandcdma: netname. TEXT = "CDMA network"; break; Case networkinterfacetype. mobilebroadbandgsm: netname. TEXT = "csm network"; break; Case networkinterfacetype. wireless80211: netname. TEXT = "wireless network"; break; Case networkinterfacetype. ethernet: netname. TEXT = "Ethernet network"; break; Case networkinterfacetype. none: netname. TEXT = "Network unavailable"; break; default: netname. TEXT = "other networks"; break ;}}}}
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.