I have an application, that requires bluetooth to send over some bytes using bluetooth. I want to app to turn on the bluetooth setting automatically when the app is launched. How do I do that?![]()
I have an application, that requires bluetooth to send over some bytes using bluetooth. I want to app to turn on the bluetooth setting automatically when the app is launched. How do I do that?![]()
Hi,
You can use BlueZ DBus Adapter to switch on/off Bluetooth.
Here the steps to switch on the device:
1. Get the Available adapter with ListAdapter method
/home/developer $ dbus-send --system --print-reply --dest=org.bluez / org.bluez.Manager.ListAdapters
method return sender=:1.200 -> dest=:1.362 reply_serial=2
array [
object path "/org/bluez/1785/hci0"
]
2. Switch on bluetooth adapter with:
dbus-send --system --type=method_call --dest=org.bluez /org/bluez/1785/hci0 org.bluez.Adapter.SetProperty string:Powered variant:boolean:true
NOTE: In Qt you have to use QDBus to call these methods [1]
List of Methods supported by Bluez Adaptor can be found at the following page: [2]
[1] http://techbase.kde.org/Development/...a_D-Bus_Method
[2] http://maemo.org/api_refs/5.0/beta/bluez/adapter.html
maybe this help:
QBluetoothLocalDevice Class Reference
Bluetooth Scanner Example
Code:QBluetoothLocalDevice *localDevice; // ... localDevice = new QBluetoothLocalDevice; // ...... // enable device localDevice->powerOn(); // disable device localDevice->setHostMode(QBluetoothLocalDevice::HostPoweredOff);