DeviceNetworkInformation class .
cellular data:蜂窝数据———————— 无线通讯技术标准的一种,G网手机通讯目前还是蜂窝。
因为小型无线通讯设备为了可移动性和其它原因,功率比较小,通讯距离也不是很远,为了可以达到远距离通讯和高效通讯及通讯管理,就需要一定量的基站进行数据处理和转发,基站的无线覆盖距离也是有限的,就需要多个基站才能覆盖整个区域,而只有基站的位置呈六边形的布局,是效率最好的,多个六边行叠加在一起就很像蜂窝了。
这种布局用到的参数也称为蜂窝数据。
不单无线通讯基站,即使一些服务行业的营业网点也是呈蜂窝的。
蜂窝数据的意思,就是你手机所有的2g/3g所走的流量,每次你网络链接是手机都会问你是否使用蜂窝数据,点是即可,如果是连接不上,即是网络设置问题。打开settigs-internet connections-connections-找到蜂窝数据链接,也就是一个白圈里头有两个蓝箭头的那个,根据sim卡服务商的gprs接入点来设置即可。如果需要代理,只需一直点next直到出现advanced,进入,选中proxies-use proxy-在HTTP proxy输入代理服务器地址,port number输入端口号,保存即可。
The DeviceNetworkInformation class supports a number of static
properties that will give you information about the phone’s network.
• IsNetworkAvailable: This is a Boolean value that indicates whether
any network is currently available.
• IsCellularDataEnabled: This is a Boolean value that indicates
whether the phone has enabled cellular data (as opposed to Wi-Fi
data).
• IsCellularDataRoamingEnabled: This is a Boolean value that indicates
whether the phone has enabled data roaming.
• IsWifiEnabled: This is a Boolean value that indicates whether the
phone has enabled Wi-Fi on the device.
• CellularMobileOperator: This returns a string that contains the
name of the mobile operator.
if (DeviceNetworkInformation.IsNetworkAvailable)
{
status.Text = "Network Found";
}
else
{
status.Text = "Network not Found";
}
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
DeviceNetworkInformation.NetworkAvailabilityChanged +=
DeviceNetworkInformation_NetworkAvailabilityChanged;
}
void DeviceNetworkInformation_NetworkAvailabilityChanged(
object sender, NetworkNotificationEventArgs e)
{
switch (e.NotificationType)
{
case NetworkNotificationType.InterfaceConnected:
status.Text = "Network Available";
break;
case NetworkNotificationType.InterfaceDisconnected:
status.Text = "Network Not Available";
break;
case NetworkNotificationType.CharacteristicUpdate:
status.Text = "Network Configuration Changed";
break;
}
}
// ...
}
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
DeviceNetworkInformation.NetworkAvailabilityChanged +=
DeviceNetworkInformation_NetworkAvailabilityChanged;
}
void DeviceNetworkInformation_NetworkAvailabilityChanged(
object sender, NetworkNotificationEventArgs e)
{
switch (e.NotificationType)
{
case NetworkNotificationType.InterfaceConnected:
status.Text = "Network Available";
break;
case NetworkNotificationType.InterfaceDisconnected:
status.Text = "Network Not Available";
break;
case NetworkNotificationType.CharacteristicUpdate:
status.Text = "Network Configuration Changed";
break;
}
}
// ...
}
The DeviceNetworkInformation class’s NetworkAvailability-
Changed event fires whenever the network changes. You can see in this
example that you can access the NotificationType from the Network-
NotificationEventArgs class to see whether a network connection
was just connected, disconnected, or just changed its configuration. In
addition, this event passes in the network type:
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
DeviceNetworkInformation.NetworkAvailabilityChanged +=
DeviceNetworkInformation_NetworkAvailabilityChanged;
}
void DeviceNetworkInformation_NetworkAvailabilityChanged(
object sender, NetworkNotificationEventArgs e)
{
switch (e.NetworkInterface.InterfaceSubtype)
{
case NetworkInterfaceSubType.Cellular_1XRTT:
case NetworkInterfaceSubType.Cellular_EDGE:
case NetworkInterfaceSubType.Cellular_GPRS:
status.Text = "Cellular (2.5G)";
break;
case NetworkInterfaceSubType.Cellular_3G:
case NetworkInterfaceSubType.Cellular_EVDO:
case NetworkInterfaceSubType.Cellular_EVDV:
status.Text = "Cellular (3G)";
break;
case NetworkInterfaceSubType.Cellular_HSPA:
status.Text = "Cellular (3.5G)";
break;
case NetworkInterfaceSubType.WiFi:
status.Text = "WiFi";
break;
case NetworkInterfaceSubType.Desktop_PassThru:
status.Text = "Desktop Connection";
break;
}
}
// ...
}
By using the NetworkInterfaceInfo class’s NetworkInterface-
SubType enumeration, you can determine the exact type of network connection
on the phone. The NetworkInterfaceInfo class also gives you
access to several other useful properties, including the following.
• Band This is an integer that specifies the speed of the network
interface.
• Characteristics: This is an enumeration that specifies whether the
phone is currently roaming or not.
• Description: This is a description of the network interface.
• InterfaceName: This is the name of the network interface.
• InterfaceState: This states whether the network interface is connected
or disconnected.
Ethernet Network Connections
Ethernet connections are only available if the phone is hooked up to a
computer via a USB cable. This is a common way to tell if the user is
plugged into a computer.
By using this DeviceNetworkInformation class, you can have
access to much of the network information that you will need for your
application.