Hi @Vishal2 Bansal ,
.NET does not provide built-in APIs for directly controlling Bluetooth.
You can try using the Windows.Devices.Bluetooth namespace.
using System;
using System.Runtime.InteropServices;
using Windows.Devices.Bluetooth;
using Windows.Devices.Enumeration;
namespace BluetoothExample
{
public class BluetoothManager
{
[DllImport("bthprops.cpl", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern int BluetoothEnableDiscovery(IntPtr hwndCaller, bool fEnabled);
[DllImport("bthprops.cpl", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern int BluetoothEnableIncomingConnections(IntPtr hwndCaller, bool fEnabled);
public static void EnableBluetooth()
{
BluetoothEnableDiscovery(IntPtr.Zero, true);
BluetoothEnableIncomingConnections(IntPtr.Zero, true);
}
public static void DisableBluetooth()
{
BluetoothEnableDiscovery(IntPtr.Zero, false);
BluetoothEnableIncomingConnections(IntPtr.Zero, false);
}
}
}
Best Regards.
Jiachen Li
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.