Is there a way to programmatically check the status of airplane mode?

I am creating a project in which I need an API to find out the status of airplane mode in Windows Phone. Or any other way to find out the status.

+6
source share
2 answers

I don’t know about any direct API that directly refers to the status of airplane mode, but in fact it disables network availability, so you can check this using DeviceNetworkInformation . (It is a good idea to test this on the device, but I believe that this will simulate the flight 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 want to ask the user to turn it on or off, you can start the configuration using ConnectionStatusTask .

+1
source

You can use the DeviceNetworkInformation class to determine network access status. If you need an event for this, you can use DeviceNetworkInformation.NetworkAvailabilityChanged .

Exmple:

 DeviceNetworkInformation.NetworkAvailabilityChanged += new EventHandler<NetworkNotificationEventArgs>(ChangeDetected); 
0
source

Source: https://habr.com/ru/post/948763/


All Articles