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

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

问题描述

我创建中,我需要的API知道在Windows phone.or任何其他方式知道状态飞行模式状态的项目。

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天全站免登陆