Wojciech Ketrzynski
Wojciech Ketrzynski

Reputation: 2651

How can I tell if a phone is connected by wifi or has access to mobile internet via C#?

When the phone is in the local network it has ip 192.168.0.x when it is outside wifi access it uses internet connection provided by mobile network(the internet accessed when you have sim inside the phone).

How to determine by C# which kind of connection is used at the time?

EDIT:

NetworkInterfaceInfo netInterfaceInfo = socket.GetCurrentNetworkInterface();
    var type = netInterfaceInfo.InterfaceType;
    var subType = netInterfaceInfo.InterfaceSubtype;

Upvotes: 0

Views: 624

Answers (1)

Chris Shao
Chris Shao

Reputation: 8231

You can try this method to check network states:

public static string GetNetStates()
{
    var info = Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType;
    switch (info)
    {
        case NetworkInterfaceType.MobileBroadbandCdma:
            return "CDMA";
        case NetworkInterfaceType.MobileBroadbandGsm:
            return "CSM";
        case NetworkInterfaceType.Wireless80211:
            return "WiFi";
        case NetworkInterfaceType.Ethernet:
            return "Ethernet";
        case NetworkInterfaceType.None:
            return "None";
        default:
            return "Other";
    }   
}

Upvotes: 3

Related Questions