Are there APIs to enable/disable Bluetooth on Windows 8.1?

南笙酒味 提交于 2019-12-05 03:13:03

问题


In Windows 8/8.1 it's now possible to enable/disable Bluetooth via the OS itself (see image below). This is awesome because it's device/driver-agnostic.

On Android, this is possible via BluetoothAdapter.enable() and BluetoothAdapter.disable(), but I haven't been able to find anything to do this on Windows (even though it seems like it's definitely possible).

So I've tried using:

  • BluetoothEnableIncomingConnections() - However, this only prevents new incoming connections. It doesn't disable existing ones.
  • devcon.exe - The problem with this method is that A. it is a non-redistributable binary B. it requires that you know he device ID ahead of time (so it's not device/driver-agnostic). Also, while it's not a dealbreaker, it'd be nice to not require elevation.
  • UI Automation - Simply launching the PC Settings app and toggling the switch with keyboard events is easy, but it's super ugly, both in terms of proper coding practices and in terms of user experience. That being said, this is the only way I've found to achieve the behavior I'm looking for so far.

I'm writing a native Win32 app in C++, so I'm not constrained to any Windows Store app requirements, although, it would be great if there was an approach that didn't require elevation.

TL;DR

Are there any APIs, WMI interfaces, or anything else available to achieve functionally equivalent results to flipping the Bluetooth toggle switch? If not, are there any alternative methods which yield similar results?


回答1:


In win8.1 you should be able to call BluetoothEnableRadio to enable/disable the local radio.

Basically the manufacturers should include a method to accomplish this so you don't have to load a dll.

"Beginning with Windows 8.1 vendors are no longer required to implement radio on/off capability (for Bluetooth 4.0 radios) in a software DLL as described in this topic, because the operating system now handles this functionality. Windows 8.1 will ignore any such DLL, even if present."

check out this link which talks about it: http://msdn.microsoft.com/en-us/library/windows/hardware/hh450832%28v=vs.85%29.aspx



来源:https://stackoverflow.com/questions/24235524/are-there-apis-to-enable-disable-bluetooth-on-windows-8-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!