Grahamvs
Grahamvs

Reputation: 679

Get Bluetooth status on Tizen Wearable

I'm creating a watch face for my Gear 2 Neo (using Tizen Wearable SDK), and I've spent hours looking (with no luck) for a way to determine if the bluetooth is enabled or not (and if possible if it's connected).

I've tried looking at the Tizen.SystemInfo API documents, but I can't find anything. I've even tried tizen.systeminfo.getPropertyValue(); with "BLUETOOTH" / "NETWORK" as the property name, but this doesn't work. It seems the Tizen.Bluetooth namespace isn't usable either.

I know there must be a way, as I have seen several watch faces out there that are able to get the status.

Is anyone able to help me out / point me in the right direction?

Edit:

Using tizen.bluetooth.getDefaultAdapter(); returns the following: "The application does not have the privilege to call this method"

Upvotes: 0

Views: 725

Answers (1)

Srabani Patra
Srabani Patra

Reputation: 78

Yes, it is possible.

To get the bluetooth status, you need to first get the defaultAdapter using following API

var blueAdapter = tizen.bluetooth.getDefaultAdapter();
console.log(blueAdapter); // To log the object
       /* Output of above log
          BluetoothAdapter
          address: ""
          name: ""
          powered: false
          visible: true
       */

if (blueAdapter.powered) {
    // Bluetooth is on, you can off using
    blueAdapter.setPowered(false);
} else {
    // Bluetooth is off, you can switch on using
    blueAdapter.setPowered(true);
}

Don't forget to add the privilege in config.xml of your app.

<tizen:privilege name="http://tizen.org/privilege/bluetooth.gap"/>

Note: Whenever you try to use platform, you need to provide the corresponding privilege in your apps config.xml file

Upvotes: 2

Related Questions