ProximityDevice.FromId(String) ProximityDevice.FromId(String) ProximityDevice.FromId(String) ProximityDevice.FromId(String) ProximityDevice.FromId(String) Method

Definition

Creates an instance of a ProximityDevice class and activates the specified proximity device interface.

public : static ProximityDevice FromId(Platform::String deviceId)
static ProximityDevice FromId(winrt::hstring deviceId) const;
public static ProximityDevice FromId(String deviceId)
Public Shared Function FromId(deviceId As String) As ProximityDevice
var proximityDevice = Windows.Networking.Proximity.ProximityDevice.fromId(deviceId);

Parameters

deviceId
String String String

The DeviceInformation Id of a proximity device.

Returns

A new ProximityDevice that uses the specified proximity device interface. Throws a System.IO.FileNotFoundException exception if the specified proximity device interface isunavailable.

Additional features and requirements

Capabilities
ID_CAP_PROXIMITY [Windows Phone] proximity ID_CAP_PROXIMITY [Windows Phone]

Examples

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);
        }
}
var proximityDevice;

function initializeProximity() {
    var selectorString = Windows.Networking.Proximity.ProximityDevice.getDeviceSelector();
            
    var propertiesToRetrieve = new Array();
    propertiesToRetrieve.push("{FB3842CD-9E2A-4F83-8FCC-4B0761139AE9} 2");

    Windows.Devices.Enumeration.DeviceInformation.findAllAsync(selectorString, propertiesToRetrieve).done(
        function (deviceInfoCollection) {
            if (deviceInfoCollection.size == 0) {
                statusDiv.innerHTML = "No proximity devices found.";
            } else {
                statusDiv.innerHTML = "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

Remarks

You can enumerate proximity devices by passing the class selection string returned by the GetDeviceSelector method to the FindAllAsync or CreateWatcher method. You can then use the resulting DeviceInformation Id value(s) to create an instance of a ProximityDevice using the FromId method.

See also