如何在 Windows Phone 10 中以编程方式检测飞行模式 [英] How to detect airplane mode programmatically in windows phone 10

查看:29
本文介绍了如何在 Windows Phone 10 中以编程方式检测飞行模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ITNOA

我想以编程方式检测 Windows Phone 10(通用 Windows 应用程序)中的飞行模式.有什么办法吗?

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

谢谢

推荐答案

您可以使用 文档和MobileBroadbandRadioState枚举用于UWP应用,但它是为移动运营商保留的,您不能在要上传到商店的应用中使用它.

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.

首先,您必须编辑 Package.appxmanifest 文件并添加 rescap 命名空间

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">

并添加新功能

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

这篇关于如何在 Windows Phone 10 中以编程方式检测飞行模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆