Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a list of bluetooth devices in a C# .NET framework

Tags:

c#

.net

bluetooth

I have created a simple C# .NET framework console application.

In it, I am trying to get a list of paired bluetooth devices currently connected to the computer. However, I cannot figure out, how to access any bluetooth services from within the code.

I looked around the internet, and all I could find was a way to do this in an universal windows project (UWP), where I can simply use the using Windows.Devices.Bluetooth namespace which contains everything I would need, however in the .NET framework console application, this namespace is not available.

I don't need any advanced way to work with the bluetooth, all I need is a list of currently connected and paired bluetooth devices.

like image 799
Askerman Avatar asked Mar 09 '23 07:03

Askerman


1 Answers

Try using below code :

            BluetoothClient client = new BluetoothClient();
            List<string> items = new List<string>();
            BluetoothDeviceInfo[] devices = client.DiscoverDevicesInRange();
            foreach (BluetoothDeviceInfo d in devices)
            {
                items.Add(d.DeviceName);
            }

You will get the reference of BluetoothClient by installing 32feet.NET through Package Manager Console.

PM> Install-Package 32feet.NET -Version 3.5.0

After Installation you will get InTheHand.Net.Personal dll in the References and then add the namespace using InTheHand.Net.Sockets; in your code

Now you will be able to access BluetoothClient

Hope this helps!!

like image 79
jANVI Avatar answered Mar 19 '23 17:03

jANVI