共用方式為


ProximityDevice.FromId(String) 方法

定義

建立 ProximityDevice 類別的實例,並啟動指定的鄰近裝置介面。

public:
 static ProximityDevice ^ FromId(Platform::String ^ deviceId);
 static ProximityDevice FromId(winrt::hstring const& deviceId);
public static ProximityDevice FromId(string deviceId);
function fromId(deviceId)
Public Shared Function FromId (deviceId As String) As ProximityDevice

參數

deviceId
String

Platform::String

winrt::hstring

鄰近裝置的 DeviceInformation 識別碼

傳回

使用指定鄰近裝置介面的新 ProximityDevice 。 如果指定的鄰近裝置介面為unavailable,則會擲回 System.IO.FileNotFoundException 例外狀況。

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 方法,以列舉鄰近裝置。 然後,您可以使用產生的 DeviceInformation Id 值 (s) ,使用 FromId 方法來建立 ProximityDevice 的實例。

適用於

另請參閱