有没有办法以编程方式检查飞行模式状态? [英] Is there a way to programatically check airplane mode status?
问题描述
我正在创建项目,其中我需要 API 来了解 Windows 手机中的飞行模式状态.或任何其他方式来了解状态.
I am creating project in which i required API to know airplane mode status on in windows phone.or any other way to know status.
推荐答案
我不知道有任何直接访问飞行模式状态的直接 API,但本质上它会关闭网络可用性,因此您可以使用
I'm not aware of any direct API that accesses the status of Airplane Mode directly but essentially it shuts down network availability so you could test for that using the DeviceNetworkInformation class. (It's a good idea to test this on a device but I believe this would simulate Airplane Mode)
public bool IsAirplaneMode()
{
bool[] networks = new bool[4] { DeviceNetworkInformation.IsNetworkAvailable, DeviceNetworkInformation.IsCellularDataEnabled, DeviceNetworkInformation.IsCellularDataRoamingEnabled, DeviceNetworkInformation.IsWiFiEnabled };
return (networks.Count(n => n) < 1);
}
如果您想要求用户打开或关闭它,您可以通过 ConnectionStatusTask.
If you'd like to ask the user to turn it on or off, you can launch the setting via ConnectionStatusTask.
这篇关于有没有办法以编程方式检查飞行模式状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!