ProximityDevice.GetDeviceSelector 方法

定义

返回可用于枚举邻近设备的类选择字符串。

public:
 static Platform::String ^ GetDeviceSelector();
 static winrt::hstring GetDeviceSelector();
public static string GetDeviceSelector();
function getDeviceSelector()
Public Shared Function GetDeviceSelector () As String

返回

String

Platform::String

winrt::hstring

邻近设备的类选择字符串。

Windows 要求

应用功能
ID_CAP_PROXIMITY [Windows Phone] proximity ID_CAP_PROXIMITY [Windows Phone]

示例

Windows.Networking.Proximity.ProximityDevice proximityDevice;

private async void InitializeProximity()
{
    string selectorString = Windows.Networking.Proximity.ProximityDevice.GetDeviceSelector();

    var deviceInfoCollection =
        await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(selectorString, null);

        if (deviceInfoCollection.Count == 0)
        {
            StatusTextBlock.Text = "No proximity devices found.";
        } 
        else 
        {
            StatusTextBlock.Text = "Proximity Device id = " + deviceInfoCollection[0].Id;
            proximityDevice =
                Windows.Networking.Proximity.ProximityDevice.FromId(deviceInfoCollection[0].Id);
        }
}
Private proximityDevice As Windows.Networking.Proximity.ProximityDevice

Private Async Sub InitializeProximity()
    Dim selectorString = Windows.Networking.Proximity.ProximityDevice.GetDeviceSelector()

    Dim deviceInfoCollection =
        Await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(selectorString, {"{FB3842CD-9E2A-4F83-8FCC-4B0761139AE9} 2"})

    If deviceInfoCollection.Count = 0 Then
        StatusTextBlock.Text = "No proximity devices found."
    Else
        StatusTextBlock.Text = "Proximity Device id = " & deviceInfoCollection(0).Id
        proximityDevice =
            Windows.Networking.Proximity.ProximityDevice.FromId(deviceInfoCollection(0).Id)
    End If
End Sub

注解

可以通过将 GetDeviceSelector 方法返回的类选择字符串传递给 FindAllAsyncCreateWatcher 方法来枚举邻近感应设备。

如果计算机支持邻近感应,并且通常安装了 NFC 设备,则 GetDefault 方法将返回支持 NFC 的设备。 还可以通过查询属性“{FB3842CD-9E2A-4F83-8FCC-4B0761139AE9} 2”的设备信息来确定计算机是否安装了 NFC 设备。 在查询返回的 DeviceInformation.Properties 对象中,“{FB3842CD-9E2A-4F83-8FCC-4B0761139AE9} 2”键的值包含描述邻近设备功能的字符串和数组。 如果其中一个字符串是“StandardNfc”,则设备支持 NFC 协议,如 NDEF。 有关如何查询设备属性的详细信息,请参阅 如何检索设备或 PnP 对象的其他属性

适用于

另请参阅