Is there a way to programatically check airplane mode status?

后端 未结 2 372
陌清茗
陌清茗 2020-12-20 19:16

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.

2条回答
  •  渐次进展
    2020-12-20 20:04

    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);
    }
    

    If you'd like to ask the user to turn it on or off, you can launch the setting via ConnectionStatusTask.

提交回复
热议问题