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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
回答2:
You can use the DeviceNetworkInformation
class to determine the state of the network access.
If you need an event for this, you can use DeviceNetworkInformation.NetworkAvailabilityChanged
.
Exmple:
DeviceNetworkInformation.NetworkAvailabilityChanged += new EventHandler<NetworkNotificationEventArgs>(ChangeDetected);