How to get current data connectivity type (3G, Edge, Gprs) in Microsoft .NET Compact Framework?
I'm developing mobile apps using the Microsoft .NET 3.5开发者_C百科 Compact Framework.
I need to periodically check for what kind of data connectivity is up (3G, Edge, or Gprs).
Can I get this information via the .NET CF API?
You can do this without periodically checking, the Microsoft.WindowsMobile.Status namespace allows you to subscribe to particular properties associated with the data connection of the device. By setting up a SystemState subscription you can assign events when the connection changes:
using Microsoft.WindowsMobile.Status;
public void OnLoad()
{
var connectionState = new SystemState(SystemProperty.ConnectionsCellularCount);
connectionState.Changed += (o, s) =>
{
if (SystemState.CellularSystemConnectedHsdpa)
{
// show 3G Icon
}
else if (SystemState.CellularSystemConnectedGprs)
{
// show GPRS Icon
}
else if (SystemState.CellularSystemConnectedEdge)
{
// show Edge Icon
}
};
}
精彩评论