uwpwindows-10-mobile

How to detect airplane mode programmatically in windows phone 10


I want to detect airplane mode in windows phone 10 ( Universal Windows Application ) programmatically. Is there any way?


Solution

  • You can use this documentation and MobileBroadbandRadioState enum for UWP apps but it's reserved for mobile operators and you can't use it in app you want to upload to Store.

    First, you have to edit Package.appxmanifest file and add rescap namespace

    <Package
    xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
    xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
    xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
    xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
    IgnorableNamespaces="uap mp wincap rescap">
    

    and add new capability

    <rescap:Capability Name="cellularDeviceIdentity"/>
    

    In your project add this code to check airplane mode status

    var ids = MobileBroadbandAccount.AvailableNetworkAccountIds;
    var account = MobileBroadbandAccount.CreateFromNetworkAccountId(ids[0]);
    
    Debug.WriteLine(account.CurrentDeviceInformation.CurrentRadioState);