1

我正在研究钛合金的一个项目。我需要使用 Beacon 模块来使用 BLE 扫描信标。我的问题是我无法让模块工作。

我使用安装移动模块来安装模块,并在 tiapp.xml 文件中启用它。

这是我目前拥有的代码:

var Beacons = require('com.logicallabs.beacons');

function doClick(beacon) {
    if(Beacons.BeaconsModule.isEnabled()){
        alert('succes');
    }else{
        alert("suces");
    }
}

$.index.open();

当您单击标签时,该功能将启动。该模块包含 3 个类。您是否必须指定必须使用哪个类的哪个方法?

另外,当我启动该程序时,我会收到错误消息,Could not find class 'android.bluetooth.BluetoothManager并且Could not find class 'com.logicallabs.beacons.ScanService$2

4

2 回答 2

0

这是您安装的模块中包含的示例应用程序的稍微修改的代码:

var Beacons = require('com.logicallabs.beacons');

function log(text) {
    Ti.API.info(text);
}

if (Beacons.isSupported()) {
    log('Bluetooth is supported!');

    if (Beacons.isEnabled()) {
        log('Bluetooth is already enabled!');
    } else {
        log('Bluetooth is disbled; enabling now.');
        // This will eventually fire a stateChanged event with state set to
        // STATE_ON, at which point we start the scanning.
        Beacons.enable();
    }
} else {
    log('Bluetooth LE is not supported.');             
}

有关更多详细信息,请查看文档和示例应用程序。在 OSX 上,您可以在~/Library/Application Support/Titanium/modules/android/com.logicallabs.beacons/目录中找到它。

于 2014-03-25T22:22:55.213 回答
0

仅当您在 Android API 版本 >= 18 的设备上进行测试时,它才会起作用

于 2014-05-20T11:02:27.783 回答