How to check/switch the airplane mode programmatically in Windows 8?

余生长醉 提交于 2019-12-12 13:19:17

问题


I have to check if the Airplane Mode is enabled in Windows 8 and maybe switch its state. I am currently working on a C# .NET 4.0 Windows Forms application but the answers in this question shouldn't be limited by that.


回答1:


Unfortunately, there isn't a programmatic way for Metro apps to change the airplane mode in Windows 8. It is against the Metro guidelines for an application to go outside its sandbox and modify system settings like this without user permission (see the discussion at http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/1ad10725-b1b8-4723-b2c3-861900809e02).

Now, you may be able to figure out the status by using some of the functionality in the Windows.Networking.NetworkOperators namespace. Specifically, check out the MobileBroadbandRadioState and NetworkDeviceStatus enumerations.

Or, you could prompt the user to make the change by explaining how to access the setting using Windows Key + I, Change PC Settings, Wireless, Airplane Mode.




回答2:


Here is a code snippet to get the NetworkConnectivityLevel which will likely give you what you need to know. I don't know if there is a way to change it. I would doubt it because you would need to also provide a way to pick a network to connect to.

    public static NetworkConnectivityLevel GetNetworkConnectivityLevel()
    {
        ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();

        var ncl = NetworkConnectivityLevel.None;

        if (profile != null)
        {
            ncl = profile.GetNetworkConnectivityLevel();
        }

        return ncl;
    }


来源:https://stackoverflow.com/questions/11671557/how-to-check-switch-the-airplane-mode-programmatically-in-windows-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!