有没有办法以编程方式检查飞行模式状态? [英] Is there a way to programatically check airplane mode status?

查看:37
本文介绍了有没有办法以编程方式检查飞行模式状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建项目,其中我需要 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,但本质上它会关闭网络可用性,因此您可以使用 DeviceNetworkInformation 类.(在设备上进行测试是个好主意,但我相信这会模拟飞行模式)

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆