语言

Menu
Sites
Language
Bluetooth. Who knows how to manage it? Turn ON\OFF (Signature error -14, privileges)

var adapter = tizen.bluetooth.getDefaultAdapter();

Tizen Studio says: "The API(attribute) 'bluetooth' of object 'tizen' is not allowed"

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

Also "Signature error -14" somtimes appears when I'm adding that privilege without "var adapter = tizen.bluetooth.getDefaultAdapter();"

Anyways nothing works correctly...

I've been trying to use different Tizen versions: 2.4, 3.0

I'm struggling to manage a button which sets ON\OFF Bluetooth via AppControl. Please, help.

Maybe some one has done solution? I'm using this code:

  var bluetoothSwitchAppControl = new tizen.ApplicationControl('http://tizen.org/appcontrol/operation/edit', null, 'application/x-bluetooth-on-off');
  var adapter = tizen.bluetooth.getDefaultAdapter();
  //Define a callback for the launchAppControl() method:
  document.getElementById('text').textContent = "1";
  function launchSuccess() {
      console.log('Bluetooth Settings application is successfully launched.');
  }
  function launchError(error) {
      alert('An error occurred: ' + error.name + '. Please enable Bluetooth through the Settings application.');
  }
  
  //Define the reply callback of the application control which implements the ApplicationControlDataArrayReplyCallback (in mobile and wearable applications):
  var serviceReply = {
      /* Called when the launched application reports success */
  onsuccess: function(data) {
      if (adapter.powered) {
          console.log('Bluetooth is successfully turned on.');
      } else {
          console.log('Bluetooth is still switched off.');
      }
  },
  /* Called when launched application reports failure */
  onfailure: function() {
      alert('Bluetooth Settings application reported failure.');
      }
  };
  document.getElementById('text').textContent = "2";
  if (adapter.powered) {
	  document.getElementById('text').textContent = "3";
    console.log('Bluetooth is already enabled');
} else {
    console.log('Try to launch the Bluetooth Settings application.');
    tizen.application.launchAppControl(bluetoothSwitchAppControl, null, launchSuccess, launchError, serviceReply);
}
编辑者为: Anonymous 03 5月, 2019

响应

6 回复
Iqbal Hossain

hi, Just run your code and works fine almost except one warning log ( but without any problem) 

Logs:

Entered BluetoothManager.getDefaultAdapter()
Try to launch the Bluetooth Settings application. main.js:51
Bluetooth Settings application is successfully launched. main.js:25
4
Wrong listener identifier. Ignoring message.
Bluetooth is successfully turned on. 

Please add these privileges and run again. 

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

My device is Z3 with Tizen 2.4

If I set Tizen 2.4 the error -14 appears.

Only if the version is 3.0 it doesn't appear but the app doesn't work on Gear S3. The code breaks down on this line:

var adapter = tizen.bluetooth.getDefaultAdapter();

Also I can not set 3.0 Tizen in the Tizen Studio, I set it manually in the config.xml Source tab.

Tizen Studio 2.0

Jan Gründling

I have a similar problem, as soon as I add the bt privilege and run the code on the device, I get the error 

start process (install)
.....
error : -14

end process (fail)
processing result : Signature error [-14] failed
spend time for pkgcmd is [3049]ms
cmd_ret:242
    An exception occurred

 

 

 

Jan Gründling

of course i mean try to run, because it doesn't run at all...

I managet it. Just put the code to my done watch face, it works with Tizen ver 2.3.2.

But the code only turns ON the blueooth. How can I turn it off?

Iqbal Hossain

you can use this code to show user an option to turn on/off the bluetooth. And i think this is a good practice. 

var appControl = new tizen.ApplicationControl('http://tizen.org/appcontrol/operation/setting/bt_visibility',
                                              null, null, null, null, null);

tizen.application.launchAppControl(appControl, null, function() {
    console.log('launch application control succeed');
}, function(e) {
    console.log('launch application control failed. reason: ' + e.message);
}, null);