locked
Which API should I use to toggle bluetooth device (headset) state? RRS feed

  • Question

  • Hello!

    I'm trying to find a way to toggle bluetooth headset state (connected/disconnected) using a scrip or application, in a same way as Settings > BLuetooth and other device does.

    I was trying to do it witn UWP BuettothDevice API and using Win32 bluetooth API (like SetBluetoothServiceState) but did not achieve my goal.

    Could you please let me know which API should I use? 

    Monday, May 4, 2020 8:49 AM

All replies

  • Hello,

    For Win32 application, you can use connect and shutdown function of Windows Sockets to connect and disconnect a Bluetooth device. Refer to "Bluetooth and connect" and "Bluetooth and shutdown".

    For UWP application, you can refer to this official sample. Related API: BluetoothLEDevice.FromIdAsync and BluetoothLEDevice.Close.

    Please let me know if it helps.

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 5, 2020 1:51 AM
  • Thank you for quick reply, Rita!

    From docs related to BluetoothLEDevice it does not look like something that works for the case I'm interested in.
    I'm trying to build a "manager" application which would not send or receive data to the device.

    Instead, I'm looking for a way to connect a previously paired headset (if it's enabled) so system will use it as a sound device, or disconnect an active device.

    Will try Windows Sockets for now, and will mark your reply as an answer if it will work for me.

    Best regards,
    Nikita

    Tuesday, May 5, 2020 10:37 AM
  • Hello Nikita Senkov,

    Thanks for your kind reply.

    This forum is for "Discuss Windows SDK Documentation, Samples and Tools." it is Win32 C++ focused. Feel free let me know if you have any issue of Win32 solution.

    For UWP related issue you can ask a question at Microsoft Q&A - UWP for more professional support. Thanks for your cooperation.

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, May 6, 2020 9:22 AM