Bluetooth API

The Bluetooth API defines interfaces and methods to manage Bluetooth.

The following Bluetooth functionalities are provided:

For more information on the Bluetooth features, see Bluetooth Guide.

Since: 1.0

Table of Contents


Summary of Interfaces and Methods

Interface Method
BluetoothManagerObject
BluetoothManager BluetoothAdapter getDefaultAdapter ()
BluetoothAdapter void setName (DOMString name, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
void setPowered (boolean state, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
void setVisible (boolean mode, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback, optional unsigned short? timeout)
void setChangeListener (BluetoothAdapterChangeCallback listener)
void unsetChangeListener ()
void discoverDevices (BluetoothDiscoverDevicesSuccessCallback successCallback, optional ErrorCallback? errorCallback)
void stopDiscovery (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
void getKnownDevices (BluetoothDeviceArraySuccessCallback successCallback, optional ErrorCallback? errorCallback)
void getDevice (BluetoothAddress address, BluetoothDeviceSuccessCallback successCallback, optional ErrorCallback? errorCallback)
void createBonding (BluetoothAddress address, BluetoothDeviceSuccessCallback successCallback, optional ErrorCallback? errorCallback)
void destroyBonding (BluetoothAddress address, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
void registerRFCOMMServiceByUUID (BluetoothUUID uuid, DOMString name, BluetoothServiceSuccessCallback successCallback, optional ErrorCallback? errorCallback)
BluetoothProfileHandler getBluetoothProfileHandler (BluetoothProfileType profileType)
BluetoothDevice void connectToServiceByUUID (BluetoothUUID uuid, BluetoothSocketSuccessCallback successCallback, optional ErrorCallback? errorCallback)
BluetoothSocket unsigned long writeData (byte[] data)
byte[] readData ()
void close ()
BluetoothClass boolean hasService (unsigned short service)
BluetoothClassDeviceMajor
BluetoothClassDeviceMinor
BluetoothClassDeviceService
BluetoothServiceHandler void unregister (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
BluetoothProfileHandler
BluetoothHealthProfileHandler void registerSinkApplication (unsigned short dataType, DOMString name, BluetoothHealthApplicationSuccessCallback successCallback, optional ErrorCallback? errorCallback)
void connectToSource (BluetoothDevice peer, BluetoothHealthApplication application, BluetoothHealthChannelSuccessCallback successCallback, optional ErrorCallback? errorCallback)
BluetoothHealthApplication void unregister (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
BluetoothHealthChannel void close ()
unsigned long sendData (byte[] data)
void setListener (BluetoothHealthChannelChangeCallback listener)
void unsetListener ()
BluetoothAdapterChangeCallback void onstatechanged (boolean powered)
void onnamechanged (DOMString name)
void onvisibilitychanged (boolean visible)
BluetoothDeviceSuccessCallback void onsuccess (BluetoothDevice device)
BluetoothDeviceArraySuccessCallback void onsuccess (BluetoothDevice[] devices)
BluetoothDiscoverDevicesSuccessCallback void onstarted ()
void ondevicefound (BluetoothDevice device)
void ondevicedisappeared (BluetoothAddress address)
void onfinished (BluetoothDevice[] foundDevices)
BluetoothSocketSuccessCallback void onsuccess (BluetoothSocket socket)
BluetoothServiceSuccessCallback void onsuccess (BluetoothServiceHandler handler)
BluetoothHealthApplicationSuccessCallback void onsuccess (BluetoothHealthApplication application)
BluetoothHealthChannelSuccessCallback void onsuccess (BluetoothHealthChannel channel)
BluetoothHealthChannelChangeCallback void onmessage (byte[] data)
void onclose ()

1. Type Definitions

1.1. BluetoothAddress

The address of a Bluetooth device.
    typedef DOMString BluetoothAddress;

Since: 1.0

1.2. BluetoothUUID

The UUID of a Bluetooth service.
    typedef DOMString BluetoothUUID;

Since: 1.0

1.3. BluetoothSocketState

Specified the Bluetooth socket state.
    enum BluetoothSocketState { "CLOSED", "OPEN" };

Since: 1.0

1.4. BluetoothProfileType

Specifies the Bluetooth profile.
    enum BluetoothProfileType { "HEALTH" };

Since: 2.2

1.5. BluetoothHealthChannelType

Specifies the channel type of health device profile.
    enum BluetoothHealthChannelType { "RELIABLE", "STREAMING" };

Since: 2.2

2. Interfaces

2.1. BluetoothManagerObject

The BluetoothManagerObject interface defines what is instantiated by the Tizen object from the Tizen platform.
    [NoInterfaceObject] interface BluetoothManagerObject {
        readonly attribute BluetoothManager bluetooth;
    };
    Tizen implements BluetoothManagerObject;

Since: 1.0

The tizen.bluetooth object allows access to the Bluetooth API.

2.2. BluetoothManager

The BluetoothManager interface provides access to the BluetoothAdapter object.
    [NoInterfaceObject] interface BluetoothManager {
        readonly attribute BluetoothClassDeviceMajor deviceMajor;
        readonly attribute BluetoothClassDeviceMinor deviceMinor;
        readonly attribute BluetoothClassDeviceService deviceService;
        BluetoothAdapter getDefaultAdapter() raises(WebAPIException);
    };

Since: 1.0

Attributes

  • readonly BluetoothClassDeviceMajor deviceMajor
    The major device class identifier of Bluetooth class of device (CoD).

    Since: 1.0

  • readonly BluetoothClassDeviceMinor deviceMinor
    The minor device class identifier of Bluetooth class of device (CoD).

    Since: 1.0

  • readonly BluetoothClassDeviceService deviceService
    The major service class identifier of Bluetooth class of device (CoD).

    Since: 1.0

Methods

getDefaultAdapter
Gets the default local Bluetooth adapter.
BluetoothAdapter getDefaultAdapter();
             

Since: 1.0

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.gap

Return value:

BluetoothAdapter The local BluetoothAdapter object.

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type UnknownError, if any other error occurs.

Code example:

 try {
     var adapter = tizen.bluetooth.getDefaultAdapter() ;
 } catch (err) {
     console.log (err.name +": " + err.message);
 }
 

2.3. BluetoothAdapter

The BluetoothAdapter interface provides access to control the device's Bluetooth adapter.
    [NoInterfaceObject] interface BluetoothAdapter {
        readonly attribute DOMString name;
        readonly attribute BluetoothAddress address;
        readonly attribute boolean powered;
        readonly attribute boolean visible;

        void setName(DOMString name,
                     optional SuccessCallback? successCallback,
                     optional ErrorCallback? errorCallback) raises(WebAPIException);

        void setPowered(boolean state,
                        optional SuccessCallback? successCallback,
                        optional ErrorCallback? errorCallback) raises(WebAPIException);

        void setVisible(boolean mode,
                        optional SuccessCallback? successCallback,
                        optional ErrorCallback? errorCallback,
                        optional unsigned short? timeout) raises(WebAPIException);

        void setChangeListener(BluetoothAdapterChangeCallback listener) raises(WebAPIException);

        void unsetChangeListener() raises(WebAPIException);

        void discoverDevices(BluetoothDiscoverDevicesSuccessCallback successCallback,
                             optional ErrorCallback? errorCallback) raises(WebAPIException);

        void stopDiscovery(optional SuccessCallback? successCallback,
                           optional ErrorCallback? errorCallback) raises(WebAPIException);

        void getKnownDevices(BluetoothDeviceArraySuccessCallback successCallback,
                             optional ErrorCallback? errorCallback) raises(WebAPIException);

        void getDevice(BluetoothAddress address,
                       BluetoothDeviceSuccessCallback successCallback,
                       optional ErrorCallback? errorCallback) raises(WebAPIException);

        void createBonding(BluetoothAddress address,
                           BluetoothDeviceSuccessCallback successCallback,
                           optional ErrorCallback? errorCallback) raises(WebAPIException);

        void destroyBonding(BluetoothAddress address,
                            optional SuccessCallback? successCallback,
                            optional ErrorCallback? errorCallback) raises(WebAPIException);



        void registerRFCOMMServiceByUUID(BluetoothUUID uuid,
                                         DOMString name,
                                         BluetoothServiceSuccessCallback successCallback,
                                         optional ErrorCallback? errorCallback) raises(WebAPIException);

        BluetoothProfileHandler getBluetoothProfileHandler(BluetoothProfileType profileType) raises(WebAPIException);
    };

Since: 1.0

This interface offers methods to control local Bluetooth behavior, such as:

  • Turning on/off Bluetooth radio
  • Changing device visibility
  • Scanning for remote devices
  • Accessing known devices
  • Registering a service in the device service database

Attributes

  • readonly DOMString name
    The readable name of the Bluetooth adapter.

    Since: 1.0

    Code example:

     // Access adapter name
     var adapter = tizen.bluetooth.getDefaultAdapter();
     console.log ("Bluetooth adapter name: " + adapter.name);
     
  • readonly BluetoothAddress address
    The unique hardware address of the Bluetooth adapter, also known as the MAC address.

    Since: 1.0

    Code example:

     var adapter = tizen.bluetooth.getDefaultAdapter();
     console.log("Bluetooth device address: " + adapter.address);
     
  • readonly boolean powered
    The current state of the Bluetooth adapter.

    This attribute holds one of the following 2 values:

    • true - If Bluetooth adapter is currently on
    • false - If Bluetooth adapter is currently off

    Since: 1.0

    Code example:

     var adapter = tizen.bluetooth.getDefaultAdapter();
     console.log("Bluetooth state: " + (adapter.powered ? "On" : "Off"));
     
  • readonly boolean visible
    The current visibility state of the Bluetooth adapter, that is, whether the local device is discoverable by remote devices.

    Since: 1.0

    Code example:

     // Queries the current visible state
     var adapter = tizen.bluetooth.getDefaultAdapter();
     console.log ("Bluetooth Visibility: " + (adapter.visible ? "On" : "Off"));
     

Methods

setName
Sets the local Bluetooth adapter name.
void setName(DOMString name, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
             

Since: 1.0

Sends a request to Bluetooth hardware to change the name of the local Bluetooth adapter to name.

The ErrorCallback is launched with these error types:

  • InvalidValuesError: If any of the input parameters contain an invalid value.
  • ServiceNotAvailableError: If a Bluetooth device is turned off.
  • UnknownError: In any other error case.
  • NotSupportedError: If a device doesn't allow a Tizen Web application to change the name of the local Bluetooth adapter.

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.admin

Remark : To check if this method is supported or not, use tizen.systeminfo.getCapability("http://tizen.org/capability/network.bluetooth.always_on")

Parameters:

  • name: Name to set
  • successCallback [optional] [nullable]: Callback function that is called when the asynchronous call completes successfully
  • errorCallback [optional] [nullable]: Callback function that is called when an error occurs

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any of the input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();

 var bt_always_on = tizen.systeminfo.getCapability("http://tizen.org/capability/network.bluetooth.always_on");

 function changeName(newName) {
     if (adapter.name != newName) {
         // initiate change name
         adapter.setName(newName, function() {
             console.log("Adapter name changed to " + adapter.name);
         },
         function(e) {
             console.log("Failed to change name: " + e.message);
         });
     }
 }
 if (bt_always_on === false) {
     changeName("myDevice");
 }
 
setPowered
Sets the state of a Bluetooth adapter to on or off by sending a request to Bluetooth hardware to change the power state. For most Bluetooth actions, the Bluetooth adapter must be powered on.

Deprecated. It is deprecated since Tizen 2.3 and will be removed in Tizen 3.0. Instead, let the user turn on/off Bluetooth through the Settings application. See Managing Bluetooth Tutorial.

void setPowered(boolean state, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
             

Since: 1.0

The ErrorCallback is launched with these error names:

  • ServiceNotAvailableError - If a Bluetooth device is busy
  • NotSupportedError: If a device does not allow a Tizen Web application to turn on or off the Bluetooth service on a device.
    Bluetooth must be enabled on the device which the remote Bluetooth devices always work with
  • UnknownError - If any other error occurs

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.admin

Remark : To check if this method is supported or not, use this.systeminfo.getCapability( "http://tizen.org/capability/network.bluetooth.always_on").

Parameters:

  • state: State to set: true to power on Bluetooth, false to power it off
  • successCallback [optional] [nullable]: Callback function that is called on successful Bluetooth activation/deactivation
  • errorCallback [optional] [nullable]: Callback function that is called on failure of a Bluetooth activation/deactivation

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any of the input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();

 function powerOn() {
      // If adapter is not powered on
      if (!adapter.powered) {
           // Initiates power on
           adapter.setPowered(true, function() {
               console.log("Bluetooth powered on success.");
           },
           function(e) {
               console.log("Failed to power on Bluetooth: " + e.message);
           });
      }
 }

 function powerOff() {
      // If powered on
      if (adapter.powered) {
           // Initiates power off
           adapter.setPowered(false, function() {
               console.log("Bluetooth powered off successfully.");
           },
           function(e) {
               console.log("Failed to power off Bluetooth: " + e.message);
           });
      }
 }

 var bt_always_on = tizen.systeminfo.getCapability("http://tizen.org/capability/network.bluetooth.always_on");
 if (bt_always_on === true) {
     console.log("Bluetooth cannot be turn off or on because this device must be always enabled.");
 } else {
     powerOn();
 }
 
setVisible
Sets the local device visibility by sending a request to a Bluetooth hardware to change the device visible state to mode.

Deprecated. It is deprecated since Tizen 2.3 and will be removed in Tizen 3.0. Instead, let the user change the Bluetooth visibility through the Settings application. See the Managing Bluetooth Tutorial.

void setVisible(boolean mode, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback, optional unsigned short? timeout);
             

Since: 1.0

If mode is true, then the device is visible to other devices, that is, it responds to inquiry calls from remote devices for time period defined (in seconds) by timeout. After the timeout, the device will become invisible.

If timeout is not passed or an invalid parameter is passed, the timeout defaults to 180 seconds (3 minutes). A timeout of 0 is considered unlimited.

The ErrorCallback is launched with these error types:

  • InvalidValuesError - If any of the input parameters contain an invalid value
  • ServiceNotAvailableError - If a Bluetooth device is turned off
  • NotSupportedError: If a device does not allow a Tizen Web application to change the visibility of the local device
    because some devices must be always discoverable from the remote Bluetooth devices
  • UnknownError - If any other error case occurs

Privilege level: platform

Privilege: http://tizen.org/privilege/bluetoothmanager

Remark : To check if this method is supported or not, use tizen.systeminfo.getCapability("http://tizen.org/capability/network.bluetooth.always_on")

Parameters:

  • mode: The boolean value to set visibility It can either be set to: true - to show the device or false - to hide the device.
  • successCallback [optional] [nullable]: Callback function that is called when changing visibility completes successfully
  • errorCallback [optional] [nullable]: Callback function that is called when an error occurs
  • timeout [optional] [nullable]: The visible timeout in seconds, used only when mode is true

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any of the input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();

 function showMe() {
      if (adapter.visible == false) {
          //Shows device
          adapter.setVisible(true,
                             function() { console.log ('Device is visible to other devices for 3 minutes.'); },
                             function(e) { console.log ('Error: ' + e.message + '(' + e.name + ')'); });
      } else {
           console.log("Device is already in discoverable mode.");
      }
 }

 function hideMe() {
     if (adapter.visible) {
          // Hides device
          adapter.setVisible(false,
                             function() { console.log('Device is in-visible now.'); },
                             function(e) { console.log ('Error: ' + e.message + '(' + e.name + ')'); });
     } else {
          console.log("Device is already in invisible mode.");
     }
 }

 var bt_always_on = tizen.systeminfo.getCapability("http://tizen.org/capability/network.bluetooth.always_on");
 if (bt_always_on === true) {
     console.log("Because Bluetooth must be always discoverable from the remote Bluetooth devices, this method does not work. NotSupportedError would be returned through ErrorCallback.");
 } else {
     powerOn();
 }
 
setChangeListener
Sets the listener to receive notifications about changes of Bluetooth adapter.
void setChangeListener(BluetoothAdapterChangeCallback listener);
             

Since: 2.2

Parameters:

  • listener: The Bluetooth Adapter event listener to set

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type.

    • with error type SecurityError, if this functionality is not allowed.

    • with error type UnknownError, if any other error occurs.

Code example:

 var changeListener = {
      onstatechanged: function(powered) {
          console.log ("Power state is changed into: " + powered);
      },
      onnamechanged: function(name) {
          console.log("Name is changed to: " + name);
      },
      onvisibilitychanged: function(visible) {
          console.log("Visibility is changed into: " + visible);
      }
 };

 var adapter = tizen.bluetooth.getDefaultAdapter();
 adapter.setChangeListener(changeListener);
 
unsetChangeListener
Unsets the listener, so stop receiving notifications about changes of Bluetooth adapter.
void unsetChangeListener();
             

Since: 2.2

Exceptions:

  • WebAPIException
    • with error type SecurityError, if this functionality is not allowed.

    • with error type UnknownError, if any other error occurs.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();

 var changeListener = {
      onstatechanged: function(powered) {
          console.log ("Power state is changed into: " + powered);
          if (!powered)
              adapter.unsetChangeListener();
      },
      onnamechanged: function(name) {
          console.log("Name is changed to: " + name);
      },
      onvisibilitychanged: function(visible) {
          console.log("Visibility is changed into: " + visible);
      }
 };

 adapter.setChangeListener(changeListener);
 
discoverDevices
Discovers nearby Bluetooth devices if any, that is, devices within proximity to the local device.
void discoverDevices(BluetoothDiscoverDevicesSuccessCallback successCallback, optional ErrorCallback? errorCallback);
             

Since: 1.0

This method initiates the device discovery process. Depending on the progress of this process the following methods are invoked:

  • BluetoothDiscoverDevicesSuccessCallback.onstarted() - when a discovery process starts successfully.
  • BluetoothDiscoverDevicesSuccessCallback.ondevicefound() - when any device is found in the process and this method is invoked with the device information. If no device is found, this method will never be invoked.
  • BluetoothDiscoverDevicesSuccessCallback.ondevicedisappeared() - when a device goes out of proximity and this method is invoked with the address of the device.
  • BluetoothDiscoverDevicesSuccessCallback.onfinished() - when a discovery process is completed.

A discovery process can be canceled anytime, by calling stopDiscovery() on the BluetoothAdapter.

The ErrorCallback is launched with these error types:

  • ServiceNotAvailableError - If a Bluetooth device is turned off
  • UnknownError - If any other error occurs

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.gap

Parameters:

  • successCallback: Callback function that is called when an asynchronous call completes successfully
  • errorCallback [optional] [nullable]: Callback function that is called when an error occurs

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any of the input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();

 function startDiscovery() {

  var discoverDevicesSuccessCallback = {
      onstarted: function() {
          console.log ("Device discovery started...");
      },
      ondevicefound: function(device) {
          console.log("Found device - name: " + device.name + ", Address: "+ device.address);
      },
      ondevicedisappeared: function(address) {
          console.log("Device disappeared: " + address);
      },
      onfinished: function(devices) {
          console.log("Found Devices");
          for (var i = 0; i < devices.length; i++) {
              console.log("Name: " + devices[i].name + ", Address: " + devices[i].address);
          }
          console.log("Total: " + devices.length);
      }
  };

  // Starts searching for nearby devices, for about 12 sec.
  adapter.discoverDevices(discoverDevicesSuccessCallback, function(e) {
      console.log ("Failed to search devices: " + e.message + "(" + e.name + ")");
  });
 }

 function onSetPoweredError(e) {
     console.log ("Could not turn on device, reason: " + e.message + "(" + e.name + ")");
 }

 adapter.setPowered(true, startDiscovery, onSetPoweredError);
 
stopDiscovery
Stops an active device discovery session.
void stopDiscovery(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
             

Since: 1.0

Device discovery is a heavyweight procedure, hence we recommend stopping discovery as soon as the required device is found. This method cancels an active discovery session.

The ErrorCallback is launched with these error types:

  • ServiceNotAvailableError - If a Bluetooth device is turned off
  • UnknownError - If any other error occurs

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.gap

Parameters:

  • successCallback [optional] [nullable]: Callback function to invoke when an asynchronous call completes successfully
  • errorCallback [optional] [nullable]: Callback function to invoke when an error occurs

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any of the input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();

 // Calls this method whenever user finds one of the device.
 function cancelDiscovery() {
    adapter.stopDiscovery(function() {
        console.log("Stop discovery success.");
    },
    function (e) {
        console.log("Error while stopDiscovery:" + e.message);
    });
 }

 function startDiscovery() {

  var discoverDevicesSuccessCallback = {
      onstarted: function() {
          console.log ("Device discovery started...") ;
      },
      ondevicefound: function(device) {
          console.log("Found device - name: " + device.name + ", Address: "+ device.address);
          // Shows the device to user to check if this is the device user is looking for.
          // For example, add this to list view.

          cancelDiscovery();
      },
      ondevicedisappeared: function(address) {
          console.log("Device disappeared: " + address);
          // Removes from list, as it is no longer valid.
      },
      onfinished: function(devices) {
          console.log("Found Devices");
          for (var i = 0; i < devices.length; i++) {
              console.log("Name: " + devices[i].name + ", Address: " + devices[i].address);
          }
          console.log("Total: " + devices.length);
      }
  };

  // Starts searching for nearby devices, for about 12 sec.
  adapter.discoverDevices(discoverDevicesSuccessCallback, function(e) {
      console.log ("Failed to search devices: " + e.message + "(" + e.name + ")");
  });
 }

 function onSetPoweredError(e) {
     console.log ("Could not turn on device, reason: " + e.message + "(" + e.name + ")");
 }

 adapter.setPowered(true, startDiscovery, onSetPoweredError);
 
getKnownDevices
Gets all the known devices that have information stored in the local Bluetooth adapter.
void getKnownDevices(BluetoothDeviceArraySuccessCallback successCallback, optional ErrorCallback? errorCallback);
             

Since: 1.0

A known device is one of the following:

  • a bonded device
  • a device found in last inquiry process

On success, it returns the list of currently known devices through BluetoothDeviceArraySuccessCallback.

The ErrorCallback is launched with these error types:

  • ServiceNotAvailableError - If a Bluetooth device is turned off
  • UnknownError - If any other error occurs

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.gap

Parameters:

  • successCallback: Callback function to invoke at retrieval of a list of Bluetooth devices that were bonded (paired) to the local Bluetooth adapter
  • errorCallback [optional] [nullable]: Callback function to invoke in case of failure in finding bonded devices

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter

    • with error type SecurityError, if the application does not have the privilege to call this method.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();

 function onGotDevices(devices) {
    console.log("Devices");
    for (var i = 0; i < devices.length; i++) {
        console.log(" Name: " + devices[i].name + ", Address: " + devices[i].address);
    }
    console.log("Total: " + devices.length);
 }

 function onError(e) {
   console.log ("Error: " + e.message);
 }

 function onBluetoothsetPowered() {
    adapter.getKnownDevices(onGotDevices, onError);
 }

 // Turns on Bluetooth
 adapter.setPowered(true, onBluetoothsetPowered);
 
getDevice
Gets the BluetoothDevice object for a given device hardware address.
void getDevice(BluetoothAddress address, BluetoothDeviceSuccessCallback successCallback, optional ErrorCallback? errorCallback);
             

Since: 1.0

This method returns device information stored in the local Bluetooth adapter for the specified device address through BluetoothDeviceSuccessCallback. A valid hardware address must be passed, such as "35:F4:59:D1:7A:03".

The ErrorCallback is launched with these error types:

  • NotFoundError - If there is no device with the given address
  • ServiceNotAvailableError - If a Bluetooth device is turned off
  • UnknownError - If any other error occurs

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.gap

Parameters:

  • address: Address of a remote Bluetooth device to get
  • successCallback: Callback function that is called when an asynchronous call completes successfully
  • errorCallback [optional] [nullable]: Callback function that is called when an error occurs

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter

    • with error type SecurityError, if the application does not have the privilege to call this method.

Code example:

 function gotDeviceInfo(device) {
    console.log("Device Name: " + device.name);
    console.log("Device Address: " + device.address);
    console.log("Device Class: " + device.deviceClass.major);
    console.log("Is Bonded: " + (device.isBonded ? "Yes" : "No"));
 }

 function onError(e) {
    console.log ("Could not get device info:" + e.message);
 }

 var adapter = tizen.bluetooth.getDefaultAdapter();
 adapter.getDevice("35:F4:59:D1:7A:03", gotDeviceInfo, onError);
 
createBonding
Creates a bond with a remote device by initiating the bonding process with peer device, using the given MAC address. The remote device must be bonded with the local device in order to connect to services of the remote device and then exchange data with each other.
void createBonding(BluetoothAddress address, BluetoothDeviceSuccessCallback successCallback, optional ErrorCallback? errorCallback);
             

Since: 1.0

If the bonding process is successful, the device information is sent in successCallback.

The ErrorCallback is launched with these error types:

  • NotFoundError - If there is no device with the given address
  • ServiceNotAvailableError - If a Bluetooth device is turned off
  • UnknownError - If any other error occurs

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.gap

Parameters:

  • address: MAC address of remote Bluetooth address to bond with
  • successCallback: Callback function that is called when an asynchronous call completes successfully
  • errorCallback [optional] [nullable]: Callback function that is called when an error occurs

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

Code example:

 function onBondingSuccess(device) {
    console.log("Device Name:" + device.name);
    console.log("Device Address:" + device.address);
    console.log("Device Service UUIDs:" + device.uuids.join("\n"));
 }

 function onError(e) {
    console.log ("Could not create bonding, reason:" + e.message);
 }

 var adapter = tizen.bluetooth.getDefaultAdapter();
 adapter.createBonding("35:F4:59:D1:7A:03", onBondingSuccess, onError);
 
destroyBonding
Destroys the bond with a remote device.
void destroyBonding(BluetoothAddress address, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
             

Since: 1.0

This method initiates the process of removing the specified address from the list of bonded devices.

The ErrorCallback is launched with these error types:

  • NotFoundError - If there is no device with the given address
  • ServiceNotAvailableError - If a Bluetooth device is turned off
  • UnknownError - If any other error occurs

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.gap

Parameters:

  • address: Address of a bonded device
  • successCallback [optional] [nullable]: Callback function that is called when an asynchronous call completes successfully
  • errorCallback [optional] [nullable]: Callback function that is called when an error occurs

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter

    • with error type SecurityError, if the application does not have the privilege to call this method.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();

 function gotDevice(device) {
    if (device.isBonded) {
      // Initiates destroying bonding
      adapter.destroyBonding(device.address, function() {
           console.log("Succeeded to destroy the bond success with:" + device.address);
       },
       function(e) {
           console.log("Failed to destroy the bond with " + device.address + ", reason: " + e.message);
       });
    }
 }

 var deviceAddress = "35:F4:59:D1:7A:03";
 adapter.getDevice(deviceAddress, gotDevice, function(e) {
     console.log("Failed to get device info for " + deviceAddress + ", reason: " + e.message);
 });
 
registerRFCOMMServiceByUUID
Registers a service record in the device service record database with the specified uuid, name.
void registerRFCOMMServiceByUUID(BluetoothUUID uuid, DOMString name, BluetoothServiceSuccessCallback successCallback, optional ErrorCallback? errorCallback);
             

Since: 1.0

On success of the service registration, it returns a BluetoothServiceHandler object as the first parameter of successCallback, and listens for client connections. The service handler can be used to be notified on client connections or to unregister the service. User interaction is mandatory to connect to a registered service.

If any client(remote device) connects to this service, then BluetoothServiceHandler.onconnect() is invoked with BluetoothSocket object.

BluetoothServiceHandler.unregister() can be used to unregister the service record from the device service database and stop listening for client connections.

The ErrorCallback is launched with these error types:

  • InvalidValuesError - If any of the input parameters contain an invalid value
  • ServiceNotAvailableError - If a Bluetooth device is turned off
  • UnknownError - If any other error occurs

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.spp

Parameters:

  • uuid: UUID of the new service, to which clients connect
  • name: Name of a service
  • successCallback: Callback function that is called on successful service registration
  • errorCallback [optional] [nullable]: Callback function that is called when an error occurs

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();
 // Holds currently registered service record
 var chatServiceHandler = null;
 // Holds currently open socket
 var serviceSocket = null;

 function chatServiceSuccessCb(recordHandler) {
    console.log("Chat service registration succeeds!");
    chatServiceHandler = recordHandler;
    recordHandler.onconnect = function(socket) {
        console.log("Client connected: " + socket.peer.name + "," + socket.peer.address);
        serviceSocket = socket;
        // Messages received from remote device
        socket.onmessage = function() {
             var data = socket.readData();
             // Handles message code goes here

        };

        socket.onclose = function() {
            console.log('The socket is closed.');
            serviceSocket = null;
        };
    };
 };

 function publishChatService() {
    var CHAT_SERVICE_UUID = "5BCE9431-6C75-32AB-AFE0-2EC108A30860";
    adapter.registerRFCOMMServiceByUUID(CHAT_SERVICE_UUID, "Chat service", chatServiceSuccessCb,
      // Error handler
      function(e) {
           console.log( "Could not register service record, Error: " + e.message);
      });
 }

 function unregisterChatService() {
      if (chatServiceHandler != null) {
          chatServiceHandler.unregister(function() {
               console.log("Chat service is unregistered");
               chatServiceHandler = null;
           }, function(e) {
               console.log("Failed to unregister service: " + e.message);
           });
      }
 }
 
getBluetoothProfileHandler
Gets the profile handler for the given type.
BluetoothProfileHandler getBluetoothProfileHandler(BluetoothProfileType profileType);
             

Since: 2.2

Remark : To check if HEATLTH type is supported or not, use tizen.systeminfo.getCapability("http://tizen.org/feature/network.bluetooth.health")

Parameters:

  • profileType: Bluetooth Profile type

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    • with error type NotSupportedError, if the given profileType is not supported on a device.

    • with error type UnknownError, if any other error occurs.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();
 var healthProfileHandler;
 var healthCapability = tizen.systeminfo.getCapability("http://tizen.org/feature/network.bluetooth.health");

 if (healthCapability) {
     healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH");
 } else {
     console.log("Bluetooth Health Profile is not supported on this device.");
 }
 

2.4. BluetoothDevice

The BluetoothDevice interface represents a remote Bluetooth device.
    [NoInterfaceObject] interface BluetoothDevice {
        readonly attribute DOMString name;
        readonly attribute BluetoothAddress address;
        readonly attribute BluetoothClass deviceClass;
        readonly attribute boolean isBonded;
        readonly attribute boolean isTrusted;
        readonly attribute boolean isConnected;
        readonly attribute BluetoothUUID[] uuids;

        void connectToServiceByUUID(BluetoothUUID uuid,
                                    BluetoothSocketSuccessCallback successCallback,
                                    optional ErrorCallback? errorCallback) raises(WebAPIException);
    };

Since: 1.0

A BluetoothDevice object can be retrieved using one of the following APIs:

  • BluetoothAdapter.getDevice()
  • BluetoothAdapter.getKnownDevices()
  • BluetoothAdapter.discoverDevices()
  • BluetoothAdapter.createBonding()

Attributes

  • readonly DOMString name
    The readable name of this remote device.

    Since: 1.0

    Code example:

     var adapter = tizen.bluetooth.getDefaultAdapter();
     adapter.getDevice("11:22:33:44:55:66", function(device) {
        console.log("Device Name: " + device.name);
     });
     
  • readonly BluetoothAddress address
    The hardware address of this remote device.

    Since: 1.0

    Code example:

     var adapter = tizen.bluetooth.getDefaultAdapter();
     adapter.getDevice("11:22:33:44:55:66", function(device) {
        console.log("Device Address: " + device.address);
     });
     
  • readonly BluetoothClass deviceClass
    The device class, which represents the type of the device and the services it provides.

    Since: 1.0

    Code example:

     var adapter = tizen.bluetooth.getDefaultAdapter();
     adapter.getDevice("11:22:33:44:55:66", function(device) {
        console.log("Device Major Class: " + device.deviceClass.major);
     });
     
  • readonly boolean isBonded
    The bond state of this remote device with the local device.

    Since: 1.0

    Code example:

     var adapter = tizen.bluetooth.getDefaultAdapter();
     adapter.getDevice("11:22:33:44:55:66", function(device) {
        console.log("Is bonded: " + (device.isBonded ? "Yes" : "No"));
     });
     
  • readonly boolean isTrusted
    The flag indicating whether the local device recognizes this remote device as a trusted device or not.

    Since: 1.0

    Code example:

     var adapter = tizen.bluetooth.getDefaultAdapter();
     adapter.getDevice("11:22:33:44:55:66", function(device) {
        console.log("Is trusted: " + (device.isTrusted ? "Yes" : "No"));
     });
     
  • readonly boolean isConnected
    The flag indicating whether the connection state of this remote device with the local device.

    Since: 1.0

    Code example:

     var adapter = tizen.bluetooth.getDefaultAdapter();
     adapter.getDevice("11:22:33:44:55:66", function(device) {
        console.log("Is connected: " + (device.isConnected ? "Yes" : "No"));
     });
     
  • readonly BluetoothUUID[] uuids
    The list of 128 bit service UUIDs available on this remote device.

    Since: 1.0

    Code example:

     var adapter = tizen.bluetooth.getDefaultAdapter();
     var CHAT_SERVICE_UUID = "5BCE9431-6C75-32AB-AFE0-2EC108A30860";
     adapter.getDevice("11:22:33:44:55:66", function(device) {
        var uuids = device.uuids;
        var services = "";
        for (var i = 0; i < uuids.length; i++) {
            services += uuids[i] + "\n";
        }
        console.log ("Services found: " + services);
        if (uuids.indexOf(CHAT_SERVICE_UUID) != -1) {
            // Connects to service
            device.connectToServiceByUUID(CHAT_SERVICE_UUID, function(socket) {
                //
                // Connected to service, handle socket
                //
            }, function (e) {
                console.log("Could not connect to chat service !!!. Error: " + e.message);
            });
        }
     });
     

Methods

connectToServiceByUUID
Connects to a specified service identified by uuid on this remote device.
void connectToServiceByUUID(BluetoothUUID uuid, BluetoothSocketSuccessCallback successCallback, optional ErrorCallback? errorCallback);
             

Since: 1.0

If opening a connection is successful, then a BluetoothSocket object with open state is sent using successCallback, through which data can be exchanged by both devices.

The ErrorCallback is launched with these error types:

  • NotFoundError - If there is no service with the specified uuid
  • InvalidValuesError - If any of the input parameters contain an invalid value
  • UnknownError - If any other error occurs

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.spp

Parameters:

  • uuid: 128 bit unique identifier, which specifies the service on the remote device
  • successCallback: Callback function that is called when when an asynchronous call completes successfully
  • errorCallback [optional] [nullable]: Callback function that is called when opening of a socket fails

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter

    • with error type SecurityError, if the application does not have the privilege to call this method.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();
 var clientSocket = null;

 // Calls a method that is invoked when user wants to send a message to a remote device.
 function sendMessage(msg) {
    // Validates socket state, if everything is ok.
    if (clientSocket != null && clientSocket.state == "OPEN") {
        // Sends the message.
        clientSocket.writeData(msg);
    }
 }

 // Calls a method that is invoked when a socket is open.
 function onSocketConnected(socket) {
    clientSocket = socket;
    console.log("Opening a socket successfully!!!");
    socket.onmessage = function () {
        var data = socket.readData();
        var recvmsg = "";
        for (var i = 0; i < data.length; i++)
        {
           recvmsg += String.fromCharCode(data[i]);
        }
        console.log("server msg >> " + recvmsg);
    };

    socket.onclose = function() {
        console.log("socket disconnected.");
    };
 }

 function onDeviceReady(device) {
    // Validates device and service uuid
    if (device.uuids.indexOf("5BCE9431-6C75-32AB-AFE0-2EC108A30860") != -1) {
       // Opens socket
       device.connectToServiceByUUID("5BCE9431-6C75-32AB-AFE0-2EC108A30860", onSocketConnected, function(e) {
           console.log ("Error connecting to service. Reason: " + e.message);
        });
    }
    else {
        console.log ("Chat service is not supported by this device");
    }
 }

 function onSetPowered() {
    // Gets the BluetoothDevice object.
    adapter.getDevice("35:F4:59:D1:7A:03", onDeviceReady, function(e) { console.log("Error: " + e.message); });
 }

 adapter.setPowered(true, onSetPowered, function(e) {console.log ("Could not turn on Bluetooth adapter. reason: " + e.message); });
 

2.5. BluetoothSocket

The BluetoothSocket interface represents the Bluetooth socket.
    [NoInterfaceObject] interface BluetoothSocket {
        readonly attribute BluetoothUUID uuid;
        readonly attribute BluetoothSocketState state;
        readonly attribute BluetoothDevice peer;
        [TreatNonCallableAsNull] attribute SuccessCallback? onmessage raises(WebAPIException);
        [TreatNonCallableAsNull] attribute SuccessCallback? onclose raises(WebAPIException);
        unsigned long writeData(byte[] data) raises(WebAPIException);


        byte[] readData() raises(WebAPIException);


        void close() raises(WebAPIException);
    };

Since: 1.0

The socket object is created by BluetoothDevice.connectToServiceByUUID() or BluetoothAdapter.registerRFCOMMServiceByUUID().

Attributes

  • readonly BluetoothUUID uuid
    The service UUID to which this socket is connected.

    Since: 1.0

  • readonly BluetoothSocketState state
    The socket state.

    Since: 1.0

  • readonly BluetoothDevice peer
    The peer device to which this socket is connected.

    Since: 1.0

  • SuccessCallback onmessage [nullable]
    Called when an incoming message is received successfully from the peer. By default, this attribute is set to null.

    Since: 1.0

    Exceptions:

    • WebAPIException
      • with error type TypeMismatchError, if any input attribute is not compatible with the expected type for this attribute.

  • SuccessCallback onclose [nullable]
    Called when the socket is closed successfully. By default, this attribute is set to null.

    Since: 1.0

    Exceptions:

    • WebAPIException
      • with error type TypeMismatchError, if any input attribute is not compatible with the expected type for this attribute.

Methods

writeData
Writes data as a sequence of bytes onto the socket and returns the number of bytes actually written.
unsigned long writeData(byte[] data);
             

Since: 1.0

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.spp

Parameters:

  • data: The data to send

Return value:

unsigned long The number of bytes actually sent

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameters in not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type UnknownError, if any other error occurs.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();

 function onSocketConnected(socket) {
    console.log ("Opened connection to remote device");
    socket.onmessage = function () {
      console.log ("Message received: " + socket.readData());
    };

    socket.onclose = function() {
       console.log("Socket closed with " + socket.peer.name);
    };

    // Sends data to peer.
    var textmsg = "Test";
    var sendtextmsg = new Array();
    for (var i = 0; i < textmsg.length; i++)
    {
        sendtextmsg[i] = textmsg.charCodeAt(i);
    }
    socket.writeData (sendtextmsg);
 }

 function onSocketError(e) {
    console.log ("Error connecting to service. Reason: " + e.message);
 }

 function onDeviceReady(device) {
    // Validates device and service uuid.
    if (device.uuids.indexOf("5BCE9431-6C75-32AB-AFE0-2EC108A30860") != -1) {
       // Opens socket
       device.connectToServiceByUUID("5BCE9431-6C75-32AB-AFE0-2EC108A30860", onSocketConnected, onSocketError );
    }
 }
 function onSetPowered() {
    // Gets the BluetoothDevice object.
    adapter.getDevice("35:F4:59:D1:7A:03", onDeviceReady, function(e) { console.log("Error: " + e.message); });
 }

 adapter.setPowered(true, onSetPowered, function(e) {console.log ("Could not turn on Bluetooth adapter. reason: " + e.message); });
 
readData
Reads data from the socket.
byte[] readData();
             

Since: 1.0

This method should be called only in the BluetoothSocket.onmessage handler, that is, when data is ready on the socket.

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.spp

Return value:

byte[] The sequence of bytes successfully read

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type UnknownError, if any other error occurs.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();

 function onError(e) {
    console.log ("Error connecting to service. Reason: " + e.message);
 }

 function onSocketConnected(socket) {
    console.log ("Opening socket success!!!");

    socket.onmessage = function() {
      //  Gets a message from peer, reads it
      var data = socket.readData();

      //
      // Code to evaluate message goes here
      //
    };

    socket.onclose = function() {
       console.log("Socket closed with " + socket.peer.name);
    };
 }

 function onDeviceReady(device) {
    // Validates device and service uuid
    if (device.uuids.indexOf("5BCE9431-6C75-32AB-AFE0-2EC108A30860") != -1) {
       // Opens socket
       device.connectToServiceByUUID("5BCE9431-6C75-32AB-AFE0-2EC108A30860", onSocketConnected, onError);
    }
 }
 function onSetPowered() {
    // Gets the BluetoothDevice object.
    adapter.getDevice("35:F4:59:D1:7A:03", onDeviceReady, function(e) { console.log("Error: " + e.message); });
 }

 adapter.setPowered(true, onSetPowered, function(e) {console.log ("Could not turn on Bluetooth adapter. reason: " + e.message); });
 
close
Closes the socket.
void close();
             

Since: 1.0

BluetoothSocket.state changes to CLOSED, and BluetoothSocket.onclose() is invoked on success.

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.spp

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type UnknownError, if any other error occurs.

2.6. BluetoothClass

The BluetoothClass interface represents Bluetooth Class of Device/Service(CoD).
    [NoInterfaceObject] interface BluetoothClass {
        readonly attribute octet major;

        readonly attribute octet minor;

        readonly attribute unsigned short [] services ;

        boolean hasService(unsigned short service) raises(WebAPIException);
    };

Since: 1.0

Bluetooth device class describes the characteristics and capabilities of a device.

Bluetooth CoD is a 24 bit integer created by the union of three components:

  • Exactly one Major Device Class(bits 8-12 of CoD) - This is the highest level of granularity for defining a Bluetooth Device.
  • Exactly one Minor Device Class(bits 2-7 of CoD) - This is to be interpreted only in the context of the Major Device Class. Thus, the meaning of these bits may change, depending on the value of 'Major Device Class'.
  • Zero or more Major Service Classes(bits 13-23) - Represents the services supported by the device.

The Major and Minor classes are intended to define a general family of devices with which any particular implementation wishes to be associated. No assumptions should be made about specific functionality or characteristics of any application, based solely on the assignment of a Major or minor device class.

Attributes

  • readonly octet major
    The major device class.

    The BluetoothClassDeviceMajor interface contains the list of known values.

    Since: 1.0

    Code example:

     var adapter = tizen.bluetooth.getDefaultAdapter();
    
     function evaluateDevice(address) {
        adapter.getDevice(address, function(device) {
            if (device.deviceClass.major == tizen.bluetooth.deviceMajor.COMPUTER) {
                // Shows computer icon for this device
                console.log("Device is computer");
            } else if (device.deviceClass.major == tizen.bluetooth.deviceMajor.PHONE) {
                // Shows phone icon
                console.log("Device is a Phone");
            }
        }, function(e) {
            console.log("Couldn't get any device with the given address: " + e.message);
        });
     }
    
     evaluateDevice("11:22:33:44:55:66");
    
     
  • readonly octet minor
    The minor device class.

    The BluetoothClassDeviceMinor interface contains the list of known values.

    Since: 1.0

  • readonly unsigned short[] services
    The services provided by this device and it refers to the BluetoothClassDeviceService interface for the list of possible values.

    Since: 1.0

Methods

hasService
Checks whether the given service exists in the services.
boolean hasService(unsigned short service);
             

Since: 1.0

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.gap

Parameters:

  • service: Service to check

Exceptions:

  • WebAPIException
    • with error type InvalidValuesError, if any of the input parameters contain an invalid value.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type UnknownError, if any other error occurs.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();
 adapter.getDevice("12:34:56:78:9A:BC", function(device) {
    if (device.deviceClass.hasService(tizen.bluetooth.deviceService.POSITIONING)) {
         console.log("Device supports Positioning service");
    }
 }, function(e) {
    console.log("Couldn't get device for given address: " + e.message);
 });
 

2.7. BluetoothClassDeviceMajor

The BluetoothClassDeviceMajor interface holds the identifiers for major device classes of Bluetooth CoD.
    [NoInterfaceObject] interface BluetoothClassDeviceMajor {

        const octet MISC = 0x00;
        const octet COMPUTER = 0x01;
        const octet PHONE = 0x02;
        const octet NETWORK = 0x03;
        const octet AUDIO_VIDEO = 0x04;
        const octet PERIPHERAL = 0x05;
        const octet IMAGING = 0x06;
        const octet WEARABLE = 0x07;
        const octet TOY = 0x08;
        const octet HEALTH = 0x09;
        const octet UNCATEGORIZED = 0x1F;
    };

Since: 1.0

2.8. BluetoothClassDeviceMinor

The BluetoothClassDeviceMinor interface holds the identifiers for minor device classes of Bluetooth CoD.
    [NoInterfaceObject] interface BluetoothClassDeviceMinor {
        const octet COMPUTER_UNCATEGORIZED = 0x00;
        const octet COMPUTER_DESKTOP = 0x01;
        const octet COMPUTER_SERVER = 0x02;
        const octet COMPUTER_LAPTOP = 0x03;
        const octet COMPUTER_HANDHELD_PC_OR_PDA = 0x04;
        const octet COMPUTER_PALM_PC_OR_PDA = 0x05;
        const octet COMPUTER_WEARABLE = 0x06;

        const octet PHONE_UNCATEGORIZED = 0x00;
        const octet PHONE_CELLULAR = 0x01;
        const octet PHONE_CORDLESS = 0x02;
        const octet PHONE_SMARTPHONE = 0x03;
        const octet PHONE_MODEM_OR_GATEWAY = 0x04;
        const octet PHONE_ISDN = 0x05;

        const octet AV_UNRECOGNIZED = 0x00;
        const octet AV_WEARABLE_HEADSET = 0x01;
        const octet AV_HANDSFREE = 0x02;
        const octet AV_MICROPHONE = 0x04;
        const octet AV_LOUDSPEAKER = 0x05;
        const octet AV_HEADPHONES = 0x06;
        const octet AV_PORTABLE_AUDIO = 0x07;
        const octet AV_CAR_AUDIO = 0x08;
        const octet AV_SETTOP_BOX = 0x09;
        const octet AV_HIFI = 0x0a;
        const octet AV_VCR = 0x0b;
        const octet AV_VIDEO_CAMERA = 0x0c;
        const octet AV_CAMCORDER = 0x0d;
        const octet AV_MONITOR = 0x0e;
        const octet AV_DISPLAY_AND_LOUDSPEAKER = 0x0f;
        const octet AV_VIDEO_CONFERENCING = 0x10;
        const octet AV_GAMING_TOY = 0x12;

        const octet PERIPHERAL_UNCATEGORIZED = 0;
        const octet PERIPHERAL_KEYBOARD = 0x10;
        const octet PERIPHERAL_POINTING_DEVICE = 0x20;
        const octet PERIPHERAL_KEYBOARD_AND_POINTING_DEVICE = 0x30;
        const octet PERIPHERAL_JOYSTICK = 0x01;
        const octet PERIPHERAL_GAMEPAD = 0x02;
        const octet PERIPHERAL_REMOTE_CONTROL = 0x03;
        const octet PERIPHERAL_SENSING_DEVICE = 0x04;
        const octet PERIPHERAL_DEGITIZER_TABLET = 0x05;
        const octet PERIPHERAL_CARD_READER = 0x06;
        const octet PERIPHERAL_DIGITAL_PEN = 0x07;
        const octet PERIPHERAL_HANDHELD_SCANNER = 0x08;
        const octet PERIPHERAL_HANDHELD_INPUT_DEVICE = 0x09;

        const octet IMAGING_UNCATEGORIZED = 0x00;
        const octet IMAGING_DISPLAY = 0x04;
        const octet IMAGING_CAMERA = 0x08;
        const octet IMAGING_SCANNER = 0x10;
        const octet IMAGING_PRINTER = 0x20;

        const octet WEARABLE_WRITST_WATCH = 0x01;
        const octet WEARABLE_PAGER = 0x02;
        const octet WEARABLE_JACKET = 0x03;
        const octet WEARABLE_HELMET = 0x04;
        const octet WEARABLE_GLASSES = 0x05;

        const octet TOY_ROBOT = 0x01;
        const octet TOY_VEHICLE = 0x02;
        const octet TOY_DOLL = 0x03;
        const octet TOY_CONTROLLER = 0x04;
        const octet TOY_GAME = 0x05;

        const octet HEALTH_UNDEFINED = 0x00;
        const octet HEALTH_BLOOD_PRESSURE_MONITOR = 0x01;
        const octet HEALTH_THERMOMETER = 0x02;
        const octet HEALTH_WEIGHING_SCALE = 0x03;
        const octet HEALTH_GLUCOSE_METER = 0x04;
        const octet HEALTH_PULSE_OXIMETER = 0x05;
        const octet HEALTH_PULSE_RATE_MONITOR = 0x06;
        const octet HEALTH_DATA_DISPLAY = 0x07;
        const octet HEALTH_STEP_COUNTER = 0x08;
        const octet HEALTH_BODY_COMPOSITION_ANALYZER = 0x09;
        const octet HEALTH_PEAK_FLOW_MONITOR = 0x0a;
        const octet HEALTH_MEDICATION_MONITOR = 0x0b;
        const octet HEALTH_KNEE_PROSTHESIS = 0x0c;
        const octet HEALTH_ANKLE_PROSTHESIS = 0x0d;
    };

Since: 1.0

2.9. BluetoothClassDeviceService

The BluetoothClassDeviceService interface holds identifiers for the major service classes of Bluetooth CoD.
    [NoInterfaceObject] interface BluetoothClassDeviceService {
        const unsigned short LIMITED_DISCOVERABILITY = 0x0001;
        const unsigned short POSITIONING = 0x0008;
        const unsigned short NETWORKING = 0x0010;
        const unsigned short RENDERING = 0x0020;
        const unsigned short CAPTURING = 0x0040;
        const unsigned short OBJECT_TRANSFER = 0x0080;
        const unsigned short AUDIO = 0x0100;
        const unsigned short TELEPHONY = 0x0200;
        const unsigned short INFORMATION = 0x0400;
    };

Since: 1.0

2.10. BluetoothServiceHandler

The BluetoothServiceHandler interface provides methods to handle Bluetooth service.
    [NoInterfaceObject] interface BluetoothServiceHandler {
        readonly attribute BluetoothUUID uuid;
        readonly attribute DOMString name;
        readonly attribute boolean isConnected;
        [TreatNonCallableAsNull] attribute BluetoothSocketSuccessCallback? onconnect raises(WebAPIException);

        void unregister(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    };

Since: 1.0

Attributes

  • readonly BluetoothUUID uuid
    The UUID of the service.

    Since: 1.0

  • readonly DOMString name
    The name of the service.

    Since: 1.0

  • readonly boolean isConnected
    The flag indicating whether any remote devices is using this service.

    Since: 1.0

  • BluetoothSocketSuccessCallback onconnect [nullable]
    Called when a remote device is connected successfully to this service. By default, this attribute is set to null.

    Since: 1.0

    Exceptions:

    • WebAPIException
      • with error type TypeMismatchError, if any input attribute is not compatible with the expected type for this attribute.

Methods

unregister
Unregisters a service record from the Bluetooth services record database and stops listening for new connections to this service.
void unregister(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
             

Since: 1.0

The ErrorCallback is launched with these error types:

  • UnknownError - If any other error occurs

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.spp

Parameters:

  • successCallback [optional] [nullable]: Callback function that is called when the record is removed successfully from the service records database
  • errorCallback [optional] [nullable]: Callback function that is called in case of failure (to unregister)

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();
 var chatServiceHandler = null;

 function chatServiceSuccessCb(handler) {
    console.log("Chat service registration was successful!");

    chatServiceHandler = handler;
    handler.onconnect = function(socket) {
       console.log("Client is connected: " + socket.peer.name + "," + socket.peer.address);
       socket.onmessage = function() {
           var data = socket.readData();
           // Handle message code goes here
           //....
       };

       // Expected close
       socket.onclose = function() {
           console.log('The socket is closed.');
       };
    };
 }

 function publishChatService() {
    var CHAT_SERVICE_UUID = "5BCE9431-6C75-32AB-AFE0-2EC108A30860";
    adapter.registerRFCOMMServiceByUUID(CHAT_SERVICE_UUID, "Chat service", chatServiceSuccessCb,
      // Error handler
      function(e) {
           console.log( "Could not register service record, Error: " + e.message);
      });
 }

 function unRegisterChatService() {
      if (chatServiceHandler != null) {
           chatServiceHandler.unregister(function() {
               chatServiceHandler = null;
               console.log("Chat service is unregistered.");
           },
           function(e) {
               console.log ("Error: " + e.message);
           });
      }
 }
 

2.11. BluetoothProfileHandler

The BluetoothProfileHandler interface represents the Bluetooth profile handler.
    [NoInterfaceObject] interface BluetoothProfileHandler {

        readonly attribute BluetoothProfileType profileType;
    };

Since: 2.2

Attributes

  • readonly BluetoothProfileType profileType
    The Bluetooth profile type.

    Since: 2.2

2.12. BluetoothHealthProfileHandler

This interface represents the handler of Bluetooth health device profile. The BluetoothHealthProfileHandler object is created by BluetoothAdapter.getBluetoothProfileHandler().
    [NoInterfaceObject] interface BluetoothHealthProfileHandler : BluetoothProfileHandler {

        void registerSinkApplication(unsigned short dataType, DOMString name, BluetoothHealthApplicationSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);

        void connectToSource(BluetoothDevice peer, BluetoothHealthApplication application, BluetoothHealthChannelSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);

    };

Since: 2.2

Methods

registerSinkApplication
Registers an application for the Sink role.
void registerSinkApplication(unsigned short dataType, DOMString name, BluetoothHealthApplicationSuccessCallback successCallback, optional ErrorCallback? errorCallback);
             

Since: 2.2

The ErrorCallback is launched with these error types:

  • ServiceNotAvailableError - If a Bluetooth device is turned off
  • UnknownError - If any other error occurs

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.health

Parameters:

  • dataType: MDEP data type used for communication, which is referenced in the ISO/IEEE 11073-20601 spec For example, pulse oximeter is 4100 and blood pressure monitor is 4103.
  • name: Friendly name associated with sink application
  • successCallback: Callback function that is called when a sink application is registered successfully
  • errorCallback [optional] [nullable]: Callback function that is called when an error occurs

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type TypeMismatchError, if any of the input parameter is not compatible with the expected type for that parameter.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();
 var healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH");

 function healthRegisterSuccess(app) {
     console.log("Registered application: " + app.name);
 }

 function healthRegisterError(e) {
     console.log("Failed to register application: " + e.message);
 };

 healthProfileHandler.registerSinkApplication(4100, "testSinkApp", healthRegisterSuccess, healthRegisterError);
 
connectToSource
Connects to the health device which acts as the Source role.
void connectToSource(BluetoothDevice peer, BluetoothHealthApplication application, BluetoothHealthChannelSuccessCallback successCallback, optional ErrorCallback? errorCallback);
             

Since: 2.2

The ErrorCallback is launched with these error types:

  • ServiceNotAvailableError - If a Bluetooth device is turned off
  • InvalidValuesError - If any of the input parameters contain an invalid value
  • UnknownError - If any other error occurs

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.health

Parameters:

  • peer: Remote device which acts as the Source role
  • application: Registered application for the Sink role
  • successCallback: Callback function that is called when a connection is established successfully
  • errorCallback [optional] [nullable]: Callback function that is called when an error occurs

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type TypeMismatchError, if any of the input parameter is not compatible with the expected type for that parameter.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();
 var healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH");
 var registerHealthApp = null;

 function healthConnectSuccess(channel) {
     console.log("Health device is connected");
 }

 function healthConnectError(e) {
     console.log("Failed to connect to source: " + e.message);
 };

 function gotDeviceInfo(device) {
     healthProfileHandler.connectToSource(device, registerHealthApp, healthConnectSuccess, healthConnectError);
 }

 function healthRegisterSuccess(app) {
     console.log("Registered application: " + app.name);
     registerHealthApp = app;
     adapter.getDevice("35:F4:59:D1:7A:03", gotDeviceInfo);
 }

 function healthRegisterError(e) {
     console.log("Failed to register application: " + e.message);
 };

 healthProfileHandler.registerSinkApplication(4100, "testSinkApp", healthRegisterSuccess, healthRegisterError);
 

2.13. BluetoothHealthApplication

The BluetoothHealthApplication interface represents the Bluetooth health application.
    [NoInterfaceObject] interface BluetoothHealthApplication {

        readonly attribute unsigned short dataType;

        readonly attribute DOMString name;

        [TreatNonCallableAsNull] attribute BluetoothHealthChannelSuccessCallback? onconnect raises(WebAPIException);

        void unregister(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);

    };

Since: 2.2

Attributes

  • readonly unsigned short dataType
    The MDEP data type used for communication, which is referenced in the ISO/IEEE 11073-20601 spec.

    For example, pulse oximeter is 4100 and blood pressure monitor is 4103.

    Since: 2.2

  • readonly DOMString name
    The friendly name associated with sink application.

    Since: 2.2

  • BluetoothHealthChannelSuccessCallback onconnect [nullable]
    Called when a health device is connected successfully through this application.

    By default, this attribute is set to null.

    Since: 2.2

    Exceptions:

    • WebAPIException
      • with error type TypeMismatchError, if an input attribute is not compatible with the expected type for this attribute.

Methods

unregister
Unregisters this application.
void unregister(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
             

Since: 2.2

The ErrorCallback is launched with these error types:

  • ServiceNotAvailableError - If a Bluetooth device is turned off
  • UnknownError - If any other error occurs

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.health

Parameters:

  • successCallback [optional] [nullable]: Callback function that is called when a sink application is registered successfully
  • errorCallback [optional] [nullable]: Callback function that is called when an error occurs

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type TypeMismatchError, if any of the input parameter is not compatible with the expected type for that parameter.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();
 var healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH");
 var healthApp = null;

 function healthRegisterSuccess(app) {
     console.log("Registered application: " + app.name);
     healthApp = app;
     healthApp.onconnect = function(channel) {
         console.log("Connected!!");
     };
 }

 function healthRegisterError(e) {
     console.log("Failed to register application: " + e.message);
 };

 function startSink() {
     try {
         healthProfileHandler.registerSinkApplication(4100, "testSinkApp", healthRegisterSuccess, healthRegisterError);
     } catch(e) {
         console.log("Error: " + e.message);
     }
 }

 function stopSink() {
     try {
         if (healthApp != null) {
             healthApp.unregister(function() {
                 healthApp = null;
                 console.log("Health application is unregistered.");
             },
             function(e) {
                 console.log ("Error: " + e.message);
             });
         }
     } catch(err) {
         console.log("Error: " + err.message);
     }
 }
 

2.14. BluetoothHealthChannel

The BluetoothHealthChannel interface represents the Bluetooth health channel.
    [NoInterfaceObject] interface BluetoothHealthChannel {

        readonly attribute BluetoothDevice peer;

        readonly attribute BluetoothHealthChannelType channelType;

        readonly attribute BluetoothHealthApplication application;

        readonly attribute boolean isConnected;

        void close() raises(WebAPIException);

        unsigned long sendData(byte[] data) raises(WebAPIException);

        void setListener(BluetoothHealthChannelChangeCallback listener) raises(WebAPIException);

        void unsetListener() raises(WebAPIException);

    };

Since: 2.2

Attributes

  • readonly BluetoothDevice peer
    The remote device to which this channel is connected.

    Since: 2.2

  • readonly BluetoothHealthChannelType channelType
    The type of of this channel.

    Since: 2.2

  • readonly BluetoothHealthApplication application
    The health application which is used to communicate with the remote device.

    Since: 2.2

  • readonly boolean isConnected
    The flag indicating whether any remote device is connected.

    Since: 2.2

Methods

close
Closes the connected channel. BluetoothHealthChannel.isConnected is changed to false and BluetoothHealthChannelChangeCallback.onclose is invoked when this channel is closed successfully.
void close();
             

Since: 2.2

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.health

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type ServiceNotAvailableError, if a Bluetooth device is turned off.

    • with error type UnknownError, if any other error occurs.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();
 var healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH");

 function healthRegisterSuccess(app) {
     console.log("Registered application: " + app.name);
     app.onconnect = function(channel) {;
         console.log("Health device is connected");
         channel.close();
     }
 }

 function healthRegisterError(e) {
     console.log("Failed to register application: " + e.message);
 };

 healthProfileHandler.registerSinkApplication(4100, "testSinkApp", healthRegisterSuccess, healthRegisterError);
 
sendData
Sends data and returns the number of bytes actually written.
unsigned long sendData(byte[] data);
             

Since: 2.2

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.health

Parameters:

  • data: Data to send

Return value:

unsigned long Number of bytes actually sent

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type ServiceNotAvailableError, if a Bluetooth device is turned off.

    • with error type TypeMismatchError, if any of the input parameter is not compatible with the expected type for that parameter.

    • with error type UnknownError, if any other error occurs.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();
 var healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH");

 function healthRegisterSuccess(app) {
     console.log("Registered application: " + app.name);
     app.onconnect = function(channel) {
         console.log("Health device is connected");
         channel.sendData(dataToSend);
     }
 }

 function healthRegisterError(e) {
     console.log("Failed to register application: " + e.message);
 };

 healthProfileHandler.registerSinkApplication(4100, "testSinkApp", healthRegisterSuccess, healthRegisterError);
 
setListener
Sets the listener to receive notifications.
void setListener(BluetoothHealthChannelChangeCallback listener);
             

Since: 2.2

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.health

Parameters:

  • listener: Event listener of Bluetooth health channel

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type UnknownError, if any other error occurs.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();
 var healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH");

 var channelCallback = {
     onmessage: function(data) {
         console.log("data is received")
     },
     onclose: function() {
         console.log("channel is closed");
     }
 };

 function healthRegisterSuccess(app) {
     console.log("Registered application: " + app.name);
     app.onconnect = function(channel) {;
         console.log("Health device is connected");
         channel.setListener(channelCallback);
     }
 }

 function healthRegisterError(e) {
     console.log("Failed to register application: " + e.message);
 };

 healthProfileHandler.registerSinkApplication(4100, "testSinkApp", healthRegisterSuccess, healthRegisterError);
 
unsetListener
Unsets the listener. This stops receiving notifications.
void unsetListener();
             

Since: 2.2

Privilege level: public

Privilege: http://tizen.org/privilege/bluetooth.health

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type UnknownError, if any other error occurs.

Code example:

 var adapter = tizen.bluetooth.getDefaultAdapter();
 var healthProfileHandler = adapter.getBluetoothProfileHandler("HEALTH");
 var connectedChannel = null;

 var channelCallback = {
     onmessage: function(data) {
         console.log("data is received")
     },
     onclose: function() {
         console.log("channel is closed");
         connectedChannel.unsetListener();
     }
 };

 function healthRegisterSuccess(app) {
     console.log("Registered application: " + app.name);
     app.onconnect = function(channel) {;
         console.log("Health device is connected");
         connectedChannel = channel;
         connectedChannel.setListener(channelCallback);
     }
 }

 function healthRegisterError(e) {
     console.log("Failed to register application: " + e.message);
 };

 healthProfileHandler.registerSinkApplication(4100, "testSinkApp", healthRegisterSuccess, healthRegisterError);
 

2.15. BluetoothAdapterChangeCallback

The BluetoothAdapterChangeCallback interface specifies a set of methods to be invoked when the changes of Bluetooth adapter occur.
    [Callback, NoInterfaceObject] interface BluetoothAdapterChangeCallback {
        void onstatechanged(boolean powered);
        void onnamechanged(DOMString name);
        void onvisibilitychanged(boolean visible);
    };

Since: 2.2

Methods

onstatechanged
Called when the power state is changed.
void onstatechanged(boolean powered);
             

Since: 2.2

Parameters:

  • powered: Flag indicating power state of local Bluetooth: true means power-on, false means power-off
onnamechanged
Called when the name is changed.
void onnamechanged(DOMString name);
             

Since: 2.2

Parameters:

  • name: Name of local Bluetooth
onvisibilitychanged
Called when the visibility is changed.
void onvisibilitychanged(boolean visible);
             

Since: 2.2

Parameters:

  • visible: Flag indicating visibility of local Bluetooth: true means that local Bluetooth is discoverable, false means that local Bluetooth is hidden from other devices

2.16. BluetoothDeviceSuccessCallback

The BluetoothDeviceSuccessCallback interface implements the success callback BluetoothAdapter.getDevice() and BluetoothAdapter.createBonding().
    [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothDeviceSuccessCallback {
        void onsuccess(BluetoothDevice device);
    };

Since: 1.0

Methods

onsuccess
Called on success.
void onsuccess(BluetoothDevice device);
             

Since: 1.0

Parameters:

  • device: BluetoothDevice object

2.17. BluetoothDeviceArraySuccessCallback

The BluetoothDeviceArraySuccessCallback interface that defines the success callback for BluetoothAdapter.getKnownDevices().
    [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothDeviceArraySuccessCallback {
        void onsuccess(BluetoothDevice[] devices);
    };

Since: 1.0

Methods

onsuccess
Called when device information is ready.
void onsuccess(BluetoothDevice[] devices);
             

Since: 1.0

Parameters:

  • devices: List of devices known to local Bluetooth adapter Each element is a BluetoothDevice.

2.18. BluetoothDiscoverDevicesSuccessCallback

The BluetoothDiscoverDevicesSuccessCallback interface that defines the success callback for BluetoothAdapter.discoverDevices().
    [Callback, NoInterfaceObject] interface BluetoothDiscoverDevicesSuccessCallback {
        void onstarted();
        void ondevicefound(BluetoothDevice device);
        void ondevicedisappeared(BluetoothAddress address);
        void onfinished(BluetoothDevice[] foundDevices);
    };

Since: 1.0

Methods

onstarted
Called at the beginning of a device discovery process for finding the nearby Bluetooth device.
void onstarted();
             

Since: 1.0

ondevicefound
Called when a new device is discovered in the process of inquiry/discovery.
void ondevicefound(BluetoothDevice device);
             

Since: 1.0

Parameters:

  • device: Device that is found
ondevicedisappeared
Called when a device is lost from proximity. After that, this device is no longer visible.
void ondevicedisappeared(BluetoothAddress address);
             

Since: 1.0

Parameters:

  • address: Address of the device that is no longer in range or visible
onfinished
Called when the device discovery process has finished.
void onfinished(BluetoothDevice[] foundDevices);
             

Since: 1.0

Parameters:

  • foundDevices: Array of devices found in this discovery session

2.19. BluetoothSocketSuccessCallback

The BluetoothSocketSuccessCallback interface that defines the success method for BluetoothDevice.connectToServiceByUUID().
    [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothSocketSuccessCallback {
        void onsuccess(BluetoothSocket socket);
    };

Since: 1.0

Methods

onsuccess
Called when the connection to a service is ready.
void onsuccess(BluetoothSocket socket);
             

Since: 1.0

Parameters:

  • socket: Socket to connect to the specified service on a remote device

2.20. BluetoothServiceSuccessCallback

The BluetoothServiceSuccessCallback interface implements the success callback for BluetoothAdapter.registerRFCOMMServiceByUUID().
    [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothServiceSuccessCallback {
        void onsuccess(BluetoothServiceHandler handler);
    };

Since: 1.0

Methods

onsuccess
Called when registering a service with the local device is successful.
void onsuccess(BluetoothServiceHandler handler);
             

Since: 1.0

Parameters:

  • handler: Bluetooth service handler

2.21. BluetoothHealthApplicationSuccessCallback

The BluetoothHealthApplicationSuccessCallback interface that defines the success method for BluetoothHealthProfileHandler.registerSinkApplication().
    [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothHealthApplicationSuccessCallback {
        void onsuccess(BluetoothHealthApplication application);
    };

Since: 2.2

Methods

onsuccess
Called when the application is registered successfully.
void onsuccess(BluetoothHealthApplication application);
             

Since: 2.2

Parameters:

  • application: Registered health application

2.22. BluetoothHealthChannelSuccessCallback

The BluetoothHealthChannelSuccessCallback interface that defines the success method for BluetoothHealthProfileHandler.connectToSource() and the event callback for BluetoothHealthApplication.onconnect.
    [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothHealthChannelSuccessCallback {
        void onsuccess(BluetoothHealthChannel channel);
    };

Since: 2.2

Methods

onsuccess
Called when a connection is established.
void onsuccess(BluetoothHealthChannel channel);
             

Since: 2.2

Parameters:

  • channel: Connected health channel

2.23. BluetoothHealthChannelChangeCallback

The BluetoothHealthChannelChangeCallback interface specifies a set of methods to be invoked when the changes of heath channel occur.
    [Callback, NoInterfaceObject] interface BluetoothHealthChannelChangeCallback {
        void onmessage(byte[] data);

        void onclose();
    };

Since: 2.2

Methods

onmessage
Called when the message is received.
void onmessage(byte[] data);
             

Since: 2.2

Parameters:

  • data: Received data
onclose
Called when the health channel is closed.
void onclose();
             

Since: 2.2

3. Related Feature

You can check if this API is supported with tizen.systeminfo.getCapability() and decide enable/disable codes that need this API.

To guarantee that the Bluetooth application runs on a device with Bluetooth feature, declare the following feature requirements in the config file:

  • http://tizen.org/feature/network.bluetooth
  • To guarantee that the Bluetooth healthcare application runs on a device with Bluetooth health profile feature, declare the following feature requirements in the config file:

  • http://tizen.org/feature/network.bluetooth.health
  • For more information, see Application Filtering.

    4. Full WebIDL

    module Bluetooth {
        typedef DOMString BluetoothAddress;
    
        typedef DOMString BluetoothUUID;
    
        enum BluetoothSocketState { "CLOSED", "OPEN" };
    
        enum BluetoothProfileType { "HEALTH" };
    
        enum BluetoothHealthChannelType { "RELIABLE", "STREAMING" };
    
        [NoInterfaceObject] interface BluetoothManagerObject {
            readonly attribute BluetoothManager bluetooth;
        };
        Tizen implements BluetoothManagerObject;
    
        [NoInterfaceObject] interface BluetoothManager {
            readonly attribute BluetoothClassDeviceMajor deviceMajor;
            readonly attribute BluetoothClassDeviceMinor deviceMinor;
            readonly attribute BluetoothClassDeviceService deviceService;
            BluetoothAdapter getDefaultAdapter() raises(WebAPIException);
        };
    
    
        [NoInterfaceObject] interface BluetoothAdapter {
            readonly attribute DOMString name;
            readonly attribute BluetoothAddress address;
            readonly attribute boolean powered;
            readonly attribute boolean visible;
    
            void setName(DOMString name,
                         optional SuccessCallback? successCallback,
                         optional ErrorCallback? errorCallback) raises(WebAPIException);
    
            void setPowered(boolean state,
                            optional SuccessCallback? successCallback,
                            optional ErrorCallback? errorCallback) raises(WebAPIException);
    
            void setVisible(boolean mode,
                            optional SuccessCallback? successCallback,
                            optional ErrorCallback? errorCallback,
                            optional unsigned short? timeout) raises(WebAPIException);
    
            void setChangeListener(BluetoothAdapterChangeCallback listener) raises(WebAPIException);
    
            void unsetChangeListener() raises(WebAPIException);
    
            void discoverDevices(BluetoothDiscoverDevicesSuccessCallback successCallback,
                                 optional ErrorCallback? errorCallback) raises(WebAPIException);
    
            void stopDiscovery(optional SuccessCallback? successCallback,
                               optional ErrorCallback? errorCallback) raises(WebAPIException);
    
            void getKnownDevices(BluetoothDeviceArraySuccessCallback successCallback,
                                 optional ErrorCallback? errorCallback) raises(WebAPIException);
    
            void getDevice(BluetoothAddress address,
                           BluetoothDeviceSuccessCallback successCallback,
                           optional ErrorCallback? errorCallback) raises(WebAPIException);
    
            void createBonding(BluetoothAddress address,
                               BluetoothDeviceSuccessCallback successCallback,
                               optional ErrorCallback? errorCallback) raises(WebAPIException);
    
            void destroyBonding(BluetoothAddress address,
                                optional SuccessCallback? successCallback,
                                optional ErrorCallback? errorCallback) raises(WebAPIException);
    
    
    
            void registerRFCOMMServiceByUUID(BluetoothUUID uuid,
                                             DOMString name,
                                             BluetoothServiceSuccessCallback successCallback,
                                             optional ErrorCallback? errorCallback) raises(WebAPIException);
    
            BluetoothProfileHandler getBluetoothProfileHandler(BluetoothProfileType profileType) raises(WebAPIException);
        };
    
        [NoInterfaceObject] interface BluetoothDevice {
            readonly attribute DOMString name;
            readonly attribute BluetoothAddress address;
            readonly attribute BluetoothClass deviceClass;
            readonly attribute boolean isBonded;
            readonly attribute boolean isTrusted;
            readonly attribute boolean isConnected;
            readonly attribute BluetoothUUID[] uuids;
    
            void connectToServiceByUUID(BluetoothUUID uuid,
                                        BluetoothSocketSuccessCallback successCallback,
                                        optional ErrorCallback? errorCallback) raises(WebAPIException);
        };
        [NoInterfaceObject] interface BluetoothSocket {
            readonly attribute BluetoothUUID uuid;
            readonly attribute BluetoothSocketState state;
            readonly attribute BluetoothDevice peer;
            [TreatNonCallableAsNull] attribute SuccessCallback? onmessage raises(WebAPIException);
            [TreatNonCallableAsNull] attribute SuccessCallback? onclose raises(WebAPIException);
            unsigned long writeData(byte[] data) raises(WebAPIException);
    
    
            byte[] readData() raises(WebAPIException);
    
    
            void close() raises(WebAPIException);
        };
    
        [NoInterfaceObject] interface BluetoothClass {
            readonly attribute octet major;
    
            readonly attribute octet minor;
    
            readonly attribute unsigned short [] services ;
    
            boolean hasService(unsigned short service) raises(WebAPIException);
        };
    
        [NoInterfaceObject] interface BluetoothClassDeviceMajor {
    
            const octet MISC = 0x00;
            const octet COMPUTER = 0x01;
            const octet PHONE = 0x02;
            const octet NETWORK = 0x03;
            const octet AUDIO_VIDEO = 0x04;
            const octet PERIPHERAL = 0x05;
            const octet IMAGING = 0x06;
            const octet WEARABLE = 0x07;
            const octet TOY = 0x08;
            const octet HEALTH = 0x09;
            const octet UNCATEGORIZED = 0x1F;
        };
    
        [NoInterfaceObject] interface BluetoothClassDeviceMinor {
            const octet COMPUTER_UNCATEGORIZED = 0x00;
            const octet COMPUTER_DESKTOP = 0x01;
            const octet COMPUTER_SERVER = 0x02;
            const octet COMPUTER_LAPTOP = 0x03;
            const octet COMPUTER_HANDHELD_PC_OR_PDA = 0x04;
            const octet COMPUTER_PALM_PC_OR_PDA = 0x05;
            const octet COMPUTER_WEARABLE = 0x06;
    
            const octet PHONE_UNCATEGORIZED = 0x00;
            const octet PHONE_CELLULAR = 0x01;
            const octet PHONE_CORDLESS = 0x02;
            const octet PHONE_SMARTPHONE = 0x03;
            const octet PHONE_MODEM_OR_GATEWAY = 0x04;
            const octet PHONE_ISDN = 0x05;
    
            const octet AV_UNRECOGNIZED = 0x00;
            const octet AV_WEARABLE_HEADSET = 0x01;
            const octet AV_HANDSFREE = 0x02;
            const octet AV_MICROPHONE = 0x04;
            const octet AV_LOUDSPEAKER = 0x05;
            const octet AV_HEADPHONES = 0x06;
            const octet AV_PORTABLE_AUDIO = 0x07;
            const octet AV_CAR_AUDIO = 0x08;
            const octet AV_SETTOP_BOX = 0x09;
            const octet AV_HIFI = 0x0a;
            const octet AV_VCR = 0x0b;
            const octet AV_VIDEO_CAMERA = 0x0c;
            const octet AV_CAMCORDER = 0x0d;
            const octet AV_MONITOR = 0x0e;
            const octet AV_DISPLAY_AND_LOUDSPEAKER = 0x0f;
            const octet AV_VIDEO_CONFERENCING = 0x10;
            const octet AV_GAMING_TOY = 0x12;
    
            const octet PERIPHERAL_UNCATEGORIZED = 0;
            const octet PERIPHERAL_KEYBOARD = 0x10;
            const octet PERIPHERAL_POINTING_DEVICE = 0x20;
            const octet PERIPHERAL_KEYBOARD_AND_POINTING_DEVICE = 0x30;
            const octet PERIPHERAL_JOYSTICK = 0x01;
            const octet PERIPHERAL_GAMEPAD = 0x02;
            const octet PERIPHERAL_REMOTE_CONTROL = 0x03;
            const octet PERIPHERAL_SENSING_DEVICE = 0x04;
            const octet PERIPHERAL_DEGITIZER_TABLET = 0x05;
            const octet PERIPHERAL_CARD_READER = 0x06;
            const octet PERIPHERAL_DIGITAL_PEN = 0x07;
            const octet PERIPHERAL_HANDHELD_SCANNER = 0x08;
            const octet PERIPHERAL_HANDHELD_INPUT_DEVICE = 0x09;
    
            const octet IMAGING_UNCATEGORIZED = 0x00;
            const octet IMAGING_DISPLAY = 0x04;
            const octet IMAGING_CAMERA = 0x08;
            const octet IMAGING_SCANNER = 0x10;
            const octet IMAGING_PRINTER = 0x20;
    
            const octet WEARABLE_WRITST_WATCH = 0x01;
            const octet WEARABLE_PAGER = 0x02;
            const octet WEARABLE_JACKET = 0x03;
            const octet WEARABLE_HELMET = 0x04;
            const octet WEARABLE_GLASSES = 0x05;
    
            const octet TOY_ROBOT = 0x01;
            const octet TOY_VEHICLE = 0x02;
            const octet TOY_DOLL = 0x03;
            const octet TOY_CONTROLLER = 0x04;
            const octet TOY_GAME = 0x05;
    
            const octet HEALTH_UNDEFINED = 0x00;
            const octet HEALTH_BLOOD_PRESSURE_MONITOR = 0x01;
            const octet HEALTH_THERMOMETER = 0x02;
            const octet HEALTH_WEIGHING_SCALE = 0x03;
            const octet HEALTH_GLUCOSE_METER = 0x04;
            const octet HEALTH_PULSE_OXIMETER = 0x05;
            const octet HEALTH_PULSE_RATE_MONITOR = 0x06;
            const octet HEALTH_DATA_DISPLAY = 0x07;
            const octet HEALTH_STEP_COUNTER = 0x08;
            const octet HEALTH_BODY_COMPOSITION_ANALYZER = 0x09;
            const octet HEALTH_PEAK_FLOW_MONITOR = 0x0a;
            const octet HEALTH_MEDICATION_MONITOR = 0x0b;
            const octet HEALTH_KNEE_PROSTHESIS = 0x0c;
            const octet HEALTH_ANKLE_PROSTHESIS = 0x0d;
        };
    
        [NoInterfaceObject] interface BluetoothClassDeviceService {
            const unsigned short LIMITED_DISCOVERABILITY = 0x0001;
            const unsigned short POSITIONING = 0x0008;
            const unsigned short NETWORKING = 0x0010;
            const unsigned short RENDERING = 0x0020;
            const unsigned short CAPTURING = 0x0040;
            const unsigned short OBJECT_TRANSFER = 0x0080;
            const unsigned short AUDIO = 0x0100;
            const unsigned short TELEPHONY = 0x0200;
            const unsigned short INFORMATION = 0x0400;
        };
    
        [NoInterfaceObject] interface BluetoothServiceHandler {
            readonly attribute BluetoothUUID uuid;
            readonly attribute DOMString name;
            readonly attribute boolean isConnected;
            [TreatNonCallableAsNull] attribute BluetoothSocketSuccessCallback? onconnect raises(WebAPIException);
    
            void unregister(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
        };
    
        [NoInterfaceObject] interface BluetoothProfileHandler {
    
            readonly attribute BluetoothProfileType profileType;
        };
    
    
        [NoInterfaceObject] interface BluetoothHealthProfileHandler : BluetoothProfileHandler {
    
            void registerSinkApplication(unsigned short dataType, DOMString name, BluetoothHealthApplicationSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    
            void connectToSource(BluetoothDevice peer, BluetoothHealthApplication application, BluetoothHealthChannelSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    
        };
    
    
        [NoInterfaceObject] interface BluetoothHealthApplication {
    
            readonly attribute unsigned short dataType;
    
            readonly attribute DOMString name;
    
            [TreatNonCallableAsNull] attribute BluetoothHealthChannelSuccessCallback? onconnect raises(WebAPIException);
    
            void unregister(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException);
    
        };
    
        [NoInterfaceObject] interface BluetoothHealthChannel {
    
            readonly attribute BluetoothDevice peer;
    
            readonly attribute BluetoothHealthChannelType channelType;
    
            readonly attribute BluetoothHealthApplication application;
    
            readonly attribute boolean isConnected;
    
            void close() raises(WebAPIException);
    
            unsigned long sendData(byte[] data) raises(WebAPIException);
    
            void setListener(BluetoothHealthChannelChangeCallback listener) raises(WebAPIException);
    
            void unsetListener() raises(WebAPIException);
    
        };
    
    
        [Callback, NoInterfaceObject] interface BluetoothAdapterChangeCallback {
            void onstatechanged(boolean powered);
            void onnamechanged(DOMString name);
            void onvisibilitychanged(boolean visible);
        };
    
        [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothDeviceSuccessCallback {
            void onsuccess(BluetoothDevice device);
        };
    
        [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothDeviceArraySuccessCallback {
            void onsuccess(BluetoothDevice[] devices);
        };
    
        [Callback, NoInterfaceObject] interface BluetoothDiscoverDevicesSuccessCallback {
            void onstarted();
            void ondevicefound(BluetoothDevice device);
            void ondevicedisappeared(BluetoothAddress address);
            void onfinished(BluetoothDevice[] foundDevices);
        };
    
        [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothSocketSuccessCallback {
            void onsuccess(BluetoothSocket socket);
        };
    
        [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothServiceSuccessCallback {
            void onsuccess(BluetoothServiceHandler handler);
        };
    
        [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothHealthApplicationSuccessCallback {
            void onsuccess(BluetoothHealthApplication application);
        };
    
        [Callback=FunctionOnly, NoInterfaceObject] interface BluetoothHealthChannelSuccessCallback {
            void onsuccess(BluetoothHealthChannel channel);
        };
    
        [Callback, NoInterfaceObject] interface BluetoothHealthChannelChangeCallback {
            void onmessage(byte[] data);
    
            void onclose();
        };
    
    };