How to detect airplane mode programmatically in windows phone 10

…衆ロ難τιáo~ 提交于 2019-12-23 02:38:30

问题


ITNOA

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

thx


回答1:


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


来源:https://stackoverflow.com/questions/40594833/how-to-detect-airplane-mode-programmatically-in-windows-phone-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!