Я ранее был в паре с устройством Bluetooth, которое поддерживает RFCOMM. Когда мое приложение открыто, я постоянно пытаюсь подключиться к устройству, открыв RFCOMM. Таким образом мое приложение автоматически подключается, когда устройство входит в диапазон.Windows 10 - как определить, когда Bluetooth-устройство находится в диапазоне
deviceInfoCollection = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));
LogData(String.Format("Number of mldp devices is {0}", deviceInfoCollection.Count));
foreach (DeviceInformation deviceInfo in deviceInfoCollection)
{
LogData(String.Format("ID:{0}, NAME:{1}", deviceInfo.Id, deviceInfo.Name));
}
Затем запустите это на таймере:
try
{
// The first time this method is invoked by a store app, it should be called
// from a UI thread in order to display the consent prompt
// https://msdn.microsoft.com/en-us/windows.devices.bluetooth.rfcomm.rfcommdeviceservice.fromidasync
RfcommDeviceService rfcommService = await RfcommDeviceService.FromIdAsync(deviceInfo.Id);
LogData(String.Format("ID:{0}, NAME:{1}", deviceInfo.Id, deviceInfo.Name));
}
catch (Exception)
{
LogData(String.Format("Can not request rfcomm service from device ID:{0}, NAME:{1}", deviceInfo.Id, deviceInfo.Name));
}
Есть ли способ запроса, когда устройство находится в диапазоне, а не пытаться подключиться? Я бы предпочел только попытку подключения, когда устройство находится в зоне действия.