1

我正在使用Tizen的 Wearable SDK 创建表盘,虽然我可以使用blueAdapter = tizen.bluetooth.getDefaultAdapter();and检索蓝牙的电源状态bluetoothPowered = blueAdapter.powered;,但我宁愿使用蓝牙监听器而不是不断调用blueAdapter.powered.

我遇到的问题是,虽然我从 Tizen 的Bluetooth API网页直接复制并粘贴了示例代码(尽管我确实更改了适配器的名称,见下文),但我收到以下错误:'undefined' is not a function (evaluating 'blueAdapter.setChangeListener(changeListener)').

这是我正在使用的代码:

var blueAdapter = tizen.bluetooth.getDefaultAdapter();

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);
      }
 };

blueAdapter.setChangeListener(changeListener);

不确定它是否有帮助,但我正在使用以下内容privileges

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

任何帮助,将不胜感激。

4

1 回答 1

2

虽然已经有一段时间了,但您是否尝试过像下面这样更改语法?

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

这将您的侦听器对象替换为一个函数,然后该函数应在侦听器中声明所需的函数。这只是一个想法,我还没有测试它。

于 2017-03-27T10:08:16.653 回答