欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Windows Phone 7 开发之检查手机网络

程序员文章站 2022-08-21 13:18:37
using system;  using system.collections.generic;  using system.linq;  using system.n...
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 button1_click(object sender, routedeventargs e) 
        { 
            networkisavailable = microsoft.phone.net.networkinformation.networkinterface.getisnetworkavailable();//当前网络是否可用 
            _currentnetworktype = microsoft.phone.net.networkinformation.networkinterface.networkinterfacetype;//获取当前网络的类型 
  
            if (networkisavailable) 
            { 
                message.text = "联网状态"; www.2cto.com
                message.background = new solidcolorbrush(colors.green); 
            } 
            else 
            { 
                message.text = "断网状态"; 
                message.background = new solidcolorbrush(colors.red); 
            }  
  
            switch (_currentnetworktype) 
            { 
                case networkinterfacetype.mobilebroadbandcdma: 
                    netname.text = "cdma网络"; 
                    break; 
                case networkinterfacetype.mobilebroadbandgsm: 
                    netname.text = "csm网络"; 
                    break; 
                case networkinterfacetype.wireless80211: 
                    netname.text = "wireless网络"; 
                    break; 
                case networkinterfacetype.ethernet: 
                    netname.text = "ethernet网络"; 
                    break; 
                case networkinterfacetype.none: 
                    netname.text = "网络不可用"; 
                    break; 
                default: 
                    netname.text = "其他的网络"; 
                    break; 
            }        
        } 
    } 


摘自 _亚