Search code examples
tizentizen-wearable-sdk

How to get the bluetooth name/id of Samsung Gear S3 smartwatch web application


I am trying to get the bluetooth name/id in a tizen web-application running on Gear S3. On the watch, this information can be found - Settings -> Connections -> Bluetooth -> Bluetooth Gear S3(AAA1).

I want the AAA1 value programmatically. Is there any method or API to get the value in a tizen web-application ?


Solution

  • Invoke the discoverDevices function, You will find the BluetoothDevice interface on the succesCallback parameter.

    BluetoothDevice interface represents a remote Bluetooth device having the propertoes:

    DOMString name;

    BluetoothAddress address;

    BluetoothClass deviceClass;

    boolean isBonded;

    boolean isTrusted;

    boolean isConnected;

    BluetoothUUID[] uuids;

    name is the property you are looking for. In your case the name is: 'Gear S3(AAA1)'

    var adapter = tizen.bluetooth.getDefaultAdapter();
    
    var discoverDevicesSuccessCallback = {
            ondevicefound: function(device) {
                alert('Found device - name: ' + device.name);
            }
        };
    
    adapter.discoverDevices(discoverDevicesSuccessCallback, null);
    

    Add 'bluetooth.gap' privilege (for Tizen 2.3.2 and below) or 'bluetooth' privilege (for Tizen 3.0 and above) in your config.xml:

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

    Additionally, If you need only 'AAA1' instead of 'Gear S3 (AAA1)', May try a little Regular Expression and split.

    var deviceName = "Gear S3 (AAA1)";                  // Gear S3 (AAA1)
    var removePrts = deviceName.replace(/[()]/g,'');    // Gear S3 AAA1
    var shortName = removePrts.split(' ');              // Gear,S3,AAA1
    alert(shortName[2]);                                // AAA1