-
-
Notifications
You must be signed in to change notification settings - Fork 209
Testing if a device is in range
Peter Foot edited this page Apr 14, 2018
·
1 revision
If you want to test solely whether a particular device is in range then do a lookup for a 'fake' Class Id e.g.
bool inRange;
Guid fakeUuid = new Guid("{F13F471D-47CB-41d6-9609-BAD0690BF891}"); // A specially created value, so no matches.
BluetoothDeviceInfo device = ...
try {
ServiceRecord[]() records = device.GetServiceRecords(uuid);
Debug.Assert(records.Length == 0, "Why are we getting any records?? len: " + records.Length);
inRange = true;
} catch (SocketException) {
inRange = false;
}
If a device comes into range but neither it nor the local device attempt a connection nor are running discovery, then neither will know they are in range.
Access to the in-range and out-of range events are available on the Microsoft stack on Win32 and they behave as described there, see class BluetoothWin32Events.
32feet.NET - Personal Area Networking for .NET
In The Hand Ltd