Windows Phone 7 开发之检查手机网络
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 NetworkInte易做图ceType _currentNetworkType; //网络连接的类型
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
networkIsAvailable = Microsoft.Phone.Net.NetworkInformation.NetworkInte易做图ce.GetIsNetworkAvailable();//当前网络是否可用
_currentNetworkType = Microsoft.Phone.Net.NetworkInformation.NetworkInte易做图ce.NetworkInte易做图ceType;//获取当前网络的类型
if (networkIsAvailable)
{
Message.Text = "联网状态"; www.zzzyk.com
Message.Background = new SolidColorBrush(Colors.Green);
}
else
{
Message.Text = "断网状态";
Message.Background = new SolidColorBrush(Colors.Red);
}
switch (_currentNetworkType)
{
case NetworkInte易做图ceType.MobileBroadbandCdma:
netname.Text = "Cdma网络";
break;
case NetworkInte易做图ceType.MobileBroadbandGsm:
netname.Text = "Csm网络";
break;
case NetworkInte易做图ceType.Wireless80211:
netname.Text = "Wireless网络";
break;
case NetworkInte易做图ceType.Ethernet:
netname.Text = "Ethernet网络";
break;
case NetworkInte易做图ceType.None:
netname.Text = "网络不可用";
break;
default:
netname.Text = "其他的网络";
break;
}
}
}
}
摘自 _亚
补充:移动开发 , Windows Phone ,