共用方式為


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 物件的其他屬性

適用於

另請參閱