ProximityDevice.DeviceId プロパティ

定義

近接デバイスの DeviceInformation ID を 取得します。

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 ID

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" の場合、デバイスは NDEF などの NFC プロトコルをサポートします。 デバイスのプロパティを照会する方法の詳細については、「デバイス または PnP オブジェクトの追加のプロパティを取得する方法」を参照してください。

適用対象

こちらもご覧ください