detect if wlan is turned off

后端 未结 2 1975
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-23 09:52

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 chang

相关标签:
2条回答
  • 2021-01-23 10:02

    Use the IsWiFiEnabled property of DeviceNetworkInformation class

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

    Regards.

    0 讨论(0)
  • 2021-01-23 10:20

    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 讨论(0)
提交回复
热议问题