当前位置: 移动技术网 > IT编程>移动开发>WP > Windows Phone 7 开发之检查手机网络

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

2018年10月09日  | 移动技术网IT编程  | 我要评论

哥们傲剑圆月山庄,苏州电视台主持人,李梓嫣

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


摘自 _亚

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网