开发者

How to get current data connectivity type (3G, Edge, Gprs) in Microsoft .NET Compact Framework?

开发者 https://www.devze.com 2023-03-08 14:16 出处:网络
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).

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号