启用设备功能Enable device capabilities

本教程介绍如何在 Microsoft Visual Studio 中声明设备功能。This tutorial describes how to declare device capabilities in Microsoft Visual Studio. 这允许你的应用使用相机、麦克风、位置传感器以及其他设备。This enables your app to use cameras, microphones, location sensors, and other devices.

指定你的应用将使用的设备功能Specify the device capabilities your app will use

当你使用某些类型的设备时,Windows 应用要求你在应用包清单中进行指定。Windows apps require you to specify in the app package manifest when you use certain types of devices. 在 Visual Studio 中,你可以使用清单设计器声明大多数功能,也可以按照如何在程序包清单中指定设备功能(手动)所述手动添加它们。In Visual Studio, you can declare most capabilities by using Manifest Designer or you can add them manually as described in How to specify device capabilities in a package manifest (manually). 本教程假定你使用清单设计器。This tutorial assumes you're using Manifest Designer.

注意   某些类型的设备(例如打印机、扫描仪和传感器)无需在应用程序包清单中声明。Note   Some types of devices, such as printers, scanners, and sensors, don't need to be declared in the app package manifest.

  • 在 Visual Studio 解决方案资源管理器中,双击程序清单文件 Package.appxmanifestIn Visual Studio Solution Explorer, double-click the package manifest file, Package.appxmanifest.
  • 打开“功能”**** 选项卡。Open the Capabilities tab.
  • 选择你的应用使用的设备功能。Select the device capabilities that your app uses. 如果你在清单设计器中没有看到你需要的功能,请手动添加该功能。If you don't see the capability you're looking for in Manifest Designer, add it manually. 有关详细信息,请参阅如何在程序包清单中指定设备功能For more info, see How to specify device capabilities in a package manifest.
设备功能Device Capability 清单设计器Manifest Designer 描述Description
AllJoynAllJoyn 在清单设计器中可用 允许网络上支持 AllJoyn 的应用和设备发现彼此并进行交互。Allows AllJoyn-enabled apps and devices on a network to discover and interact with each other. Windows.Devices.AllJoyn 命名空间中访问 API 的应用都必须使用此功能。App apps that access APIs in the Windows.Devices.AllJoyn namespace must use this capability.
阻止的聊天消息Blocked Chat Messages 在清单设计器中可用 允许应用读取已由“垃圾邮件筛选器”应用阻止的短信和彩信消息。Allows apps to read SMS and MMS messages that have been blocked by the Spam Filter app.
聊天消息访问Chat Message Access 在清单设计器中可用 允许应用读取和删除短信。Allows apps to read and delete Text Messages. 它还允许应用将聊天消息存储在系统数据存储中。It also allows apps to store chat messages in the system data store.
代码生成Code Generation 在清单设计器中可用 允许应用以动态方式生成代码。Allows apps to generate code dynamically.
企业身份验证Enterprise Authentication 在清单设计器中可用 此功能遵循 Microsoft Store 策略。This capability is subject to the Microsoft Store policy. 它允许连接至要求提供域凭据的企业 Intranet 资源。It provides the capability to connect to enterprise intranet resources that require domain credentials. 大多数应用通常不需要此功能。This capability is not typically needed for most apps.
Internet (客户端)Internet (Client) 在清单设计器中可用 提供对 Internet 及公共场所(如机场和咖啡厅)网络的出站访问。Provides outbound access to the Internet and networks in public places like airports and coffee shops. 例如,用户将网络指定为公共网络的 Intranet 网络。For example, Intranet networks where the user has designated the network as public. 需要进行 Internet 访问的大多数应用都应使用此功能。Most apps that require Internet access should use the capability.
Internet(客户端 & 服务器)Internet (Client & Server) 在清单设计器中可用 提供对 Internet 及公共场所(如机场和咖啡厅)网络的入站和出站访问。Provides inbound and outbound access to the Internet and the networks in public places like airports and coffee shops. 此功能是“Internet (客户端)”**** 的超集。This capability is a superset of Internet (Client). 如果已启用此功能,则不需要同时启用“Internet (客户端)”****。Internet (Client) doesn't need to be enabled if this capability is also enabled. 对重要端口的入站访问始终会被阻止。Inbound access to critical ports is always blocked.
位置Location 在清单设计器中可用 提供对当前位置的访问。Provides access to the current location. 当前位置是从专用硬件(例如电脑中的 GPS 传感器)或从可用的网络信息中获取的。This is obtained from dedicated hardware like a GPS sensor in the PC, or derived from available network information.
麦克风Microphone 在清单设计器中可用 提供对麦克风的音频种子的访问。Provides access to the microphone's audio feed. 这允许应用从所连接的麦克风进行录音。This allows the app to record from connected microphones.
音乐库Music Library 在清单设计器中可用 能够添加、更改或删除本地电脑和家庭组电脑的“音乐库”**** 中的文件。Provides the capability to add, change, or delete files in the Music Library for the local PC and HomeGroup PCs.
对象 3DObjects 3D 在清单设计器中可用 提供对用户 3D 对象的编程访问权限,让应用无需用户交互即可枚举和访问库中的所有文件。Provides programmatic access to the user's 3D Objects, allowing the app to enumerate and access all files in the library without user interaction. 此功能通常用在需要访问整个 3D 对象库的 3D 应用和游戏中。This capability is typically used in 3D apps and games that need to access the entire 3D Objects library.
电话呼叫Phone Call 在清单设计器中可用 允许应用访问设备上的所有电话线路并执行以下功能:在手机上进行拨号并显示系统拨号器而不提示用户;访问与线路相关的元数据;访问与线路相关的触发器。Allows apps to access all of the phone lines on the device and perform the following functions: place a call on the phone and show the system dialer without prompting the user; access line-related metadata; access line-related triggers. 允许用户选择的垃圾邮件筛选器应用设置并检查阻止列表和呼叫来源信息。Allows the user-selected spam filter app to set and check the block list and call origin information.
图片库Pictures Library 在清单设计器中可用 提供在本地电脑和家庭组电脑中添加、更改或删除图片库文件的功能。Provides the capability to add, change, or delete files in the Pictures Library for the local PC and HomeGroup PCs.
服务点Point of Service 在清单设计器中可用 提供对服务点外设的访问权限。Provides access to Point of Service peripherals. 若要访问 Windows.Devices.PointOfService 命名空间中的 API,则需要此功能。This capability is required to access APIs in the Windows.Devices.PointOfService namespace.
专用网络(客户端和服务器)Private Networks (Client & Server) 在清单设计器中可用 针对具有经过身份验证的域控制器或用户已指定为家庭或工作网络的 Intranet 网络提供入站和出站访问。Provides inbound and outbound access to Intranet networks that have an authenticated domain controller, or that the user has designated as either home or work networks. 对重要端口的入站访问始终会被阻止。Inbound access to critical ports is always blocked.
邻近帮助Proximity 在清单设计器中可用 能够通过近距离通信 (NFC) 与靠近电脑的设备进行连接。Provides the capability to connect to devices in close proximity to the PC via near-field communication (NFC). 近距离感应可用于向附近设备上的应用发送文件或与其进行通信。Near-field proximity may be used to send files or communicate with an app on the nearby device.
可移动存储Removable Storage 在清单设计器中可用 能够添加、更改或删除可移动存储设备上的文件。Provides the capability to add, change, or delete files on removable storage devices. 应用只能访问可移动存储上使用“文件类型关联”**** 声明在清单中定义的文件类型。The app can only access the file types on removable storage that are defined in the manifest using the File Type Associations declaration. 应用无法访问家庭组电脑上的可移动存储。The app can't access removable storage on HomeGroup PCs.
共享用户证书Shared User Certificates 在清单设计器中可用 此功能遵循 Microsoft Store 策略。This capability is subject to the Microsoft Store policy. 它允许访问用于验证用户身份的软件和硬件证书,如智能卡证书。It provides the capability to access software and hardware certificates, such as smart card certificates, for validating a user's identity. 如果相关 API 在运行时被调用,用户必须执行操作(插卡、选择证书等)。When related APIs are invoked at runtime, the user must take action (insert card, select certificate, etc.). 如果你的应用通过“证书”**** 声明包含专用证书,则不需要此功能。This capability is not necessary if your app includes a private certificate via a Certificates declaration.
用户帐户信息User Account Information 在清单设计器中可用 使应用能够访问用户的名称和头像。Gives apps the ability to access the user's name and picture. 若要访问 Windows.System.UserProfile 命名空间中的某些 API,此功能是必需的。This capability is required to access some APIs in the Windows.System.UserProfile namespace.
视频库Videos Library 在清单设计器中可用 能够添加、更改或删除本地电脑和家庭组电脑的“视频库”**** 中的文件。Provides the capability to add, change, or delete files in the Videos Library for the local PC and HomeGroup PCs.
VOIP 呼叫VOIP Calling 在清单设计器中可用 允许应用访问 Windows.ApplicationModel.Calls 命名空间中的 VOIP 呼叫 API。Allows apps to access the VOIP calling APIs in the Windows.ApplicationModel.Calls namespace.
摄像头Webcam 在清单设计器中可用 提供对内置相机或附加摄像头视频源的访问权限。Provides access to the built-in camera or attached webcam's video feed. 这允许应用捕获快照和影片。This allows the app to capture snapshots and movies.
USBUSB 提供对自定义 USB 设备的访问。Provides access to custom USB devices. 此功能需要子元素。This capability requires child elements. 该功能在 Windows Phone 上不受支持。This feature is not supported on Windows Phone.
人体学接口设备 (HID)Human Interface Device (HID) 提供对人体学接口设备 (HID) 的访问。Provides access to Human Interface Devices (HID). 此功能需要子元素。This capability requires child elements. 有关详细信息,请参阅如何为 HID 指定设备功能For more info, see How to specify device capabilities for HID.
蓝牙 GATTBluetooth GATT 通过主要服务、附属服务、特征和描述符的集合提供对蓝牙 LE 设备的访问。Provides access to Bluetooth LE devices through a collection of primary services, included services, characteristics, and descriptors. 此功能需要子元素。This capability requires child elements. 有关详细信息,请参阅如何为蓝牙指定设备功能For more info, see How to specify device capabilities for Bluetooth.
Bluetooth RFCOMMBluetooth RFCOMM 提供对支持基本速率/扩展数据速率 (BR/EDR) 传输的 API 的访问,并且允许 UWP 应用访问实现了串行端口配置文件 (SPP) 的设备。Provides access to APIs that support the Basic Rate/Extended Data Rate (BR/EDR) transport and also lets your UWP app access a device that implements Serial Port Profile (SPP). 此功能需要子元素。This capability requires child elements. 有关详细信息,请参阅如何为蓝牙指定设备功能For more info, see How to specify device capabilities for Bluetooth.

使用 Windows 运行时 API 与设备进行通信Use the Windows Runtime API for communicating with your device

下表会将某些功能连接到 Windows 运行时 API。The following table connects some of the capabilities to Windows Runtime APIs.

设备功能Device Capability APIAPI
AllJoynAllJoyn Windows.Devices.AllJoynWindows.Devices.AllJoyn
阻止的聊天消息Blocked Chat Messages Windows.ApplicationModel.CommunicationBlockingWindows.ApplicationModel.CommunicationBlocking
位置Location 有关详细信息,请参阅地图和位置概述See Maps and location overview for more information.
电话呼叫Phone Call Windows.applicationmodel.resources.core。调用Windows.ApplicationModel.Calls
用户帐户信息User Account Information Windows.System。UserProfileWindows.System.UserProfile
VOIP 呼叫VOIP Calling Windows.applicationmodel.resources.core。调用Windows.ApplicationModel.Calls
USBUSB Windows.Devices.UsbWindows.Devices.Usb
HIDHID Windows.Devices.HumanInterfaceDeviceWindows.Devices.HumanInterfaceDevice
蓝牙 GATTBluetooth GATT Bluetooth.genericattributeprofile 替换。Windows.Devices.Bluetooth.GenericAttributeProfile
Bluetooth RFCOMMBluetooth RFCOMM Windows.Devices.Bluetooth.RfcommWindows.Devices.Bluetooth.Rfcomm
服务点Point of Service PointOfServiceWindows.Devices.PointOfService