Exemplo n.º 1
0
        public static async Task <BluetoothDevice> FindBluetoothDeviceByAddressAsync(
            this IBluetoothManager bluetooth, string address, uint delay)
        {
            return(await Task.Run(async() =>
            {
                await bluetooth.StartDeviceDiscoveryAsync(1000, delay);

                while (bluetooth.IsDiscovering)
                {
                    foreach (var device in bluetooth.DeviceList)
                    {
                        if (device.Address == address)
                        {
                            bluetooth.StopDiscovering();
                            return new BluetoothDevice()
                            {
                                Name = device.Name, Address = device.Address
                            };
                        }
                    }

                    Debug.WriteLine("looking fot device with address...");
                    await Task.Delay((int)delay);
                }

                return null;
            }));
        }