共用方式為


ProximityDevice.DeviceId 屬性

定義

取得鄰近裝置的 DeviceInformation 識別碼

public:
 property Platform::String ^ DeviceId { Platform::String ^ get(); };
winrt::hstring DeviceId();
public string DeviceId { get; }
var string = proximityDevice.deviceId;
Public ReadOnly Property DeviceId As String

屬性值

String

Platform::String

winrt::hstring

鄰近裝置的 DeviceInformation 識別碼

Windows 需求

應用程式功能
ID_CAP_PROXIMITY [Windows Phone] proximity ID_CAP_PROXIMITY [Windows Phone]

範例

private async void QueryDeviceProperties()
{
    // Include the proximity properties key
    var propertiesToRetrieve = new List<String> {"{FB3842CD-9E2A-4F83-8FCC-4B0761139AE9} 2"};

    var defaultProximityDevice =
        Windows.Networking.Proximity.ProximityDevice.GetDefault();

    if (defaultProximityDevice != null)
    {
        var devInfo = await Windows.Devices.Enumeration.DeviceInformation.CreateFromIdAsync(
            defaultProximityDevice.DeviceId, propertiesToRetrieve);

        if (devInfo.Properties.ContainsKey("{FB3842CD-9E2A-4F83-8FCC-4B0761139AE9} 2"))
        {
            var proximityCapabilities =
                devInfo.Properties["{FB3842CD-9E2A-4F83-8FCC-4B0761139AE9} 2"] as string[];
            if (proximityCapabilities.Contains("StandardNfc"))
            {
                // This proximity device supports NFC
            }
        }
    }
}
Private Async Sub QueryDeviceProperties()
    ' Include the proximity properties key
    Dim propertiesToRetrieve = New List(Of String) From {"{FB3842CD-9E2A-4F83-8FCC-4B0761139AE9} 2"}

    Dim defaultProximityDevice =
        Windows.Networking.Proximity.ProximityDevice.GetDefault()

    If defaultProximityDevice IsNot Nothing Then
        Dim devInfo = Await Windows.Devices.Enumeration.DeviceInformation.CreateFromIdAsync(
            defaultProximityDevice.DeviceId, propertiesToRetrieve)

        If devInfo.Properties.ContainsKey("{FB3842CD-9E2A-4F83-8FCC-4B0761139AE9} 2") Then
            Dim proximityCapabilities =
                TryCast(devInfo.Properties("{FB3842CD-9E2A-4F83-8FCC-4B0761139AE9} 2"), String())

            If proximityCapabilities.Contains("StandardNfc") Then
                ' This proximity device supports NFC
            End If
        End If
    End If
End Sub

備註

如果您的電腦支援鄰近性並已安裝 NFC 裝置,通常是這種情況, 則 GetDefault 方法會傳回支援 NFC 的裝置。 您也可以查詢屬性 「{FB3842CD-9E2A-4F83-8FCC-4B0761139AE9} 2」 的裝置資訊,來判斷您的電腦是否已安裝 NFC 裝置。 在從查詢傳回的 DeviceInformation.Properties 物件中,「{FB3842CD-9E2A-4F83-8FCC-4B0761139AE9} 2」 機碼包含和描述鄰近裝置功能的字串陣列。 如果其中一個字串是 「StandardNfc」,則裝置支援 NFC 通訊協定,例如 NDEF。 如需如何查詢裝置屬性的詳細資訊,請參閱 如何擷取裝置或 PnP 物件的其他屬性

適用於

另請參閱