1
votes

can anybody give me a hint, how to programmatically detect in C# on Windows Phone 8.1. App (not 8.0!), if the WLAN is enabled / disabled? I don't want to change these settings, just need to know...

The Solution is a Windows 8.1 universal app, and the (Windows Phone 8.1) project just references .Net for Windows Store Apps and Windows Phone 8.1. Adding the C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsPhone\v8.1\Microsoft.Phone.dll as suggested and querying the IsWiFiEnabled property does not work - Compiler error: Cannot find type System.SystemException in mscorlib.dll

Thanks, Marher

2

2 Answers

1
votes

If you're looking for a Non 8.1 Silverlight solution:

You can use the Windows.Networking.Connectivity namespace to query this.

MSDN NetworkInformation class

An example to get you started

bool is_wifi_enabled = false;
Guid adapter_id = new Guid();

// get the list of connection profiles
// we need the adpater id for the wifi
foreach (var item in NetworkInformation.GetConnectionProfiles())
{

    // check if wifi
    if (item.IsWlanConnectionProfile)
    {
        // tag the adapter
        adapter_id = item.NetworkAdapter.NetworkAdapterId;
    }
}

// get all lan adapters (this most likely will be empty if wlan is disabled)
foreach (var item in NetworkInformation.GetLanIdentifiers())
{
    if (item.NetworkAdapterId == adapter_id)
    {
        is_wifi_enabled = true;
    }
}
0
votes

Use the IsWiFiEnabled property of DeviceNetworkInformation class

You can refer to the How-To network information page if you need other network informations.

Regards.