ProximityDevice.FromId(String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
创建 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 ID 。
返回
使用指定邻近感应设备接口的新 ProximityDevice 。 如果指定的邻近设备接口不可使用,则引发 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 方法返回的类选择字符串传递给 FindAllAsync 或 CreateWatcher 方法来枚举邻近感应设备。 然后,可以使用生成的 DeviceInformation ID 值 () 使用 FromId 方法创建 ProximityDevice 的实例。